diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-08-23 18:38:41 (GMT) |
---|---|---|
committer | Steve Dower <steve.dower@python.org> | 2019-08-23 18:38:41 (GMT) |
commit | 5be666010e4df65dc4d831435cc92340ea369f94 (patch) | |
tree | a77c11ab56db4089d292ca9a4f968dd3628d5ad0 /Python | |
parent | 8f080b09953a2d862de5c74edf414a54ea3dbea5 (diff) | |
download | cpython-5be666010e4df65dc4d831435cc92340ea369f94.zip cpython-5be666010e4df65dc4d831435cc92340ea369f94.tar.gz cpython-5be666010e4df65dc4d831435cc92340ea369f94.tar.bz2 |
bpo-37549: os.dup() fails for standard streams on Windows 7 (GH-15389)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/fileutils.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index 36a3c99..0c05424 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1134,11 +1134,18 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) flags = HANDLE_FLAG_INHERIT; else flags = 0; - if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) { + + /* This check can be removed once support for Windows 7 ends. */ +#define CONSOLE_PSEUDOHANDLE(handle) (((ULONG_PTR)(handle) & 0x3) == 0x3 && \ + GetFileType(handle) == FILE_TYPE_CHAR) + + if (!CONSOLE_PSEUDOHANDLE(handle) && + !SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) { if (raise) PyErr_SetFromWindowsErr(0); return -1; } +#undef CONSOLE_PSEUDOHANDLE return 0; #else |