From: Eli Zaretskii Date: Fri, 9 Aug 2024 11:00:34 +0000 (+0300) Subject: ; * src/w32.c (init_ntproc): Fix formatting conventions in last change. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e523f86fed4465670ffef257ea15a9c36058b1b5;p=emacs.git ; * src/w32.c (init_ntproc): Fix formatting conventions in last change. (cherry picked from commit 944e45db53cb173c5eadd4794081c133e8649d67) --- diff --git a/src/w32.c b/src/w32.c index 0c1291f1094..cec15606bf2 100644 --- a/src/w32.c +++ b/src/w32.c @@ -10482,14 +10482,19 @@ init_ntproc (int dumping) { #ifdef _UCRT - /* For UCRT, the _fdopen will try to find free stream from - _IOB_ENTRIES (= 3), thus we can't reopen the standard handles - with it. Using SetHandleInformation to make the handle not - inheritable to child process is a better way. */ - SetHandleInformation (GetStdHandle(STD_INPUT_HANDLE), HANDLE_FLAG_INHERIT, 0); - SetHandleInformation (GetStdHandle(STD_OUTPUT_HANDLE), HANDLE_FLAG_INHERIT, 0); - SetHandleInformation (GetStdHandle(STD_ERROR_HANDLE), HANDLE_FLAG_INHERIT, 0); -#else + /* The non-UCRT code below relies on MSVCRT-only behavior, whereby + _fdopen reuses the first unused FILE slot, whereas UCRT skips the + first 3 slots, which correspond to stdin/stdout/stderr. That + makes it impossible in the UCRT build to open these 3 streams + once they are closed. So we use SetHandleInformation instead, + which is available on all versions of Windows that have UCRT. */ + SetHandleInformation (GetStdHandle(STD_INPUT_HANDLE), + HANDLE_FLAG_INHERIT, 0); + SetHandleInformation (GetStdHandle(STD_OUTPUT_HANDLE), + HANDLE_FLAG_INHERIT, 0); + SetHandleInformation (GetStdHandle(STD_ERROR_HANDLE), + HANDLE_FLAG_INHERIT, 0); +#else /* !_UCRT */ HANDLE parent; HANDLE stdin_save = INVALID_HANDLE_VALUE; HANDLE stdout_save = INVALID_HANDLE_VALUE; @@ -10497,8 +10502,8 @@ init_ntproc (int dumping) parent = GetCurrentProcess (); - /* ignore errors when duplicating and closing; typically the - handles will be invalid when running as a gui program. */ + /* Ignore errors when duplicating and closing; typically the + handles will be invalid when running as a gui program. */ DuplicateHandle (parent, GetStdHandle (STD_INPUT_HANDLE), parent, @@ -10544,7 +10549,7 @@ init_ntproc (int dumping) else _open ("nul", O_TEXT | O_NOINHERIT | O_WRONLY); _fdopen (2, "w"); -#endif +#endif /* !_UCRT */ } /* unfortunately, atexit depends on implementation of malloc */