diff options
author | Dong-hee Na <donghee.na@python.org> | 2021-12-13 12:57:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-13 12:57:59 (GMT) |
commit | 191c431de7d9b23484dd16f67e62c6e85a1fac7f (patch) | |
tree | 9bfef0bfce875d0deb1bd6c024d8f292ce7cbc96 /Python/pylifecycle.c | |
parent | e09705f58fc2ff3cc2720c6337ae3f48bb7cb090 (diff) | |
download | cpython-191c431de7d9b23484dd16f67e62c6e85a1fac7f.zip cpython-191c431de7d9b23484dd16f67e62c6e85a1fac7f.tar.gz cpython-191c431de7d9b23484dd16f67e62c6e85a1fac7f.tar.bz2 |
bpo-45919: Use WinAPI GetFileType() in is_valid_fd() (GH-30082)
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index b6d73a9..a9eb387 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2182,23 +2182,21 @@ is_valid_fd(int fd) #if defined(F_GETFD) && ( \ defined(__linux__) || \ defined(__APPLE__) || \ - defined(MS_WINDOWS) || \ defined(__wasm__)) - int res; - _Py_BEGIN_SUPPRESS_IPH - res = fcntl(fd, F_GETFD); - _Py_END_SUPPRESS_IPH - return res >= 0; -#elif defined(__linux__) || defined(MS_WINDOWS) - int fd2; - _Py_BEGIN_SUPPRESS_IPH - fd2 = dup(fd); + return fcntl(fd, F_GETFD) >= 0; +#elif defined(__linux__) + int fd2 = dup(fd); if (fd2 >= 0) { close(fd2); } - _Py_END_SUPPRESS_IPH - return (fd2 >= 0); +#elif defined(MS_WINDOWS) + HANDLE hfile; + _Py_BEGIN_SUPPRESS_IPH + hfile = (HANDLE)_get_osfhandle(fd); + _Py_END_SUPPRESS_IPH + return (hfile != INVALID_HANDLE_VALUE + && GetFileType(hfile) != FILE_TYPE_UNKNOWN); #else struct stat st; return (fstat(fd, &st) == 0); |