mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-45919: Use WinAPI GetFileType() in is_valid_fd() (GH-30082)
This commit is contained in:
parent
e09705f58f
commit
191c431de7
1 changed files with 10 additions and 12 deletions
|
@ -2182,23 +2182,21 @@ is_valid_fd(int fd)
|
||||||
#if defined(F_GETFD) && ( \
|
#if defined(F_GETFD) && ( \
|
||||||
defined(__linux__) || \
|
defined(__linux__) || \
|
||||||
defined(__APPLE__) || \
|
defined(__APPLE__) || \
|
||||||
defined(MS_WINDOWS) || \
|
|
||||||
defined(__wasm__))
|
defined(__wasm__))
|
||||||
int res;
|
return fcntl(fd, F_GETFD) >= 0;
|
||||||
_Py_BEGIN_SUPPRESS_IPH
|
#elif defined(__linux__)
|
||||||
res = fcntl(fd, F_GETFD);
|
int fd2 = dup(fd);
|
||||||
_Py_END_SUPPRESS_IPH
|
|
||||||
return res >= 0;
|
|
||||||
#elif defined(__linux__) || defined(MS_WINDOWS)
|
|
||||||
int fd2;
|
|
||||||
_Py_BEGIN_SUPPRESS_IPH
|
|
||||||
fd2 = dup(fd);
|
|
||||||
if (fd2 >= 0) {
|
if (fd2 >= 0) {
|
||||||
close(fd2);
|
close(fd2);
|
||||||
}
|
}
|
||||||
_Py_END_SUPPRESS_IPH
|
|
||||||
|
|
||||||
return (fd2 >= 0);
|
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
|
#else
|
||||||
struct stat st;
|
struct stat st;
|
||||||
return (fstat(fd, &st) == 0);
|
return (fstat(fd, &st) == 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue