Eryk Sun <eryk...@gmail.com> added the comment:
In Windows, GetFileType((HANDLE)_get_osfhandle(fd)) is several times faster than close(dup(fd)). For example: #if defined(MS_WINDOWS) int type; _Py_BEGIN_SUPPRESS_IPH type = GetFileType((HANDLE)_get_osfhandle(fd)); _Py_END_SUPPRESS_IPH return type != FILE_TYPE_UNKNOWN; #endif If the C file descriptor isn't assigned and flagged FOPEN, then _get_osfhandle() returns (intptr_t)-1. This is the pseudohandle value for the current process, so GetFileType() will fail with an invalid handle error, as expected. ---------- nosy: +eryksun _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45915> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com