Skip to content

Instantly share code, notes, and snippets.

@lpcdma
Last active November 11, 2017 14:33
Show Gist options
  • Save lpcdma/2a6c78f21ca0bdf51b601271d6773aef to your computer and use it in GitHub Desktop.
Save lpcdma/2a6c78f21ca0bdf51b601271d6773aef to your computer and use it in GitHub Desktop.
fix_python_win32.cpp
_PyVerify_fd(int fd)
{
// const int i1 = fd >> IOINFO_L2E;
// const int i2 = fd & ((1 << IOINFO_L2E) - 1);
// static int sizeof_ioinfo = 0;
// /* Determine the actual size of the ioinfo structure,
// * as used by the CRT loaded in memory
// */
// if (sizeof_ioinfo == 0 && __pioinfo[0] != NULL) {
// sizeof_ioinfo = _msize(__pioinfo[0]) / IOINFO_ARRAY_ELTS;
// }
// if (sizeof_ioinfo == 0) {
// /* This should not happen... */
// goto fail;
// }
// /* See that it isn't a special CLEAR fileno */
// if (fd != _NO_CONSOLE_FILENO) {
// /* Microsoft CRT would check that 0<=fd<_nhandle but we can't do that. Instead
// * we check pointer validity and other info
// */
// if (0 <= i1 && i1 < IOINFO_ARRAYS && __pioinfo[i1] != NULL) {
// /* finally, check that the file is open */
// my_ioinfo* info = (my_ioinfo*)(__pioinfo[i1] + i2 * sizeof_ioinfo);
// if (info->osfile & FOPEN) {
// return 1;
// }
// }
// }
//fail:
// errno = EBADF;
// return 0;
if (_get_osfhandle(fd) == INVALID_HANDLE_VALUE)
return 0;
else
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment