Issue #23524: Change back to using Windows errors for _Py_fstat instead of the errno shim.
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index ab9eb8c..0f226ea 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -182,7 +182,13 @@
{
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
struct _Py_stat_struct buf;
- if (_Py_fstat(fd, &buf) < 0 && errno == EBADF) {
+ if (_Py_fstat(fd, &buf) < 0 &&
+#ifdef MS_WINDOWS
+ GetLastError() == ERROR_INVALID_HANDLE
+#else
+ errno == EBADF
+#endif
+ ) {
PyObject *exc;
char *msg = strerror(EBADF);
exc = PyObject_CallFunction(PyExc_OSError, "(is)",