[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 944e45db53c 2/2: ; * src/w32.c (init_ntproc): Fix formatting conv
From: |
Eli Zaretskii |
Subject: |
master 944e45db53c 2/2: ; * src/w32.c (init_ntproc): Fix formatting conventions in last change. |
Date: |
Fri, 9 Aug 2024 07:01:01 -0400 (EDT) |
branch: master
commit 944e45db53cb173c5eadd4794081c133e8649d67
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
; * src/w32.c (init_ntproc): Fix formatting conventions in last change.
---
src/w32.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
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 */