mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #23524: Change back to using Windows errors for _Py_fstat instead of the errno shim.
This commit is contained in:
parent
35a97c0bed
commit
8acde7dcce
3 changed files with 13 additions and 5 deletions
|
@ -182,7 +182,13 @@ check_fd(int fd)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
#if defined(HAVE_FSTAT) || defined(MS_WINDOWS)
|
||||||
struct _Py_stat_struct buf;
|
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;
|
PyObject *exc;
|
||||||
char *msg = strerror(EBADF);
|
char *msg = strerror(EBADF);
|
||||||
exc = PyObject_CallFunction(PyExc_OSError, "(is)",
|
exc = PyObject_CallFunction(PyExc_OSError, "(is)",
|
||||||
|
|
|
@ -560,7 +560,7 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_Py_fstat(fd, &st) != 0) {
|
if (_Py_fstat(fd, &st) != 0) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetExcFromWindowsErr(PyExc_OSError, GetLastError());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -637,10 +637,14 @@ _Py_fstat(int fd, struct _Py_stat_struct *result)
|
||||||
else
|
else
|
||||||
h = (HANDLE)_get_osfhandle(fd);
|
h = (HANDLE)_get_osfhandle(fd);
|
||||||
|
|
||||||
|
/* Protocol violation: we explicitly clear errno, instead of
|
||||||
|
setting it to a POSIX error. Callers should use GetLastError. */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
if (h == INVALID_HANDLE_VALUE) {
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
errno = EBADF;
|
/* This is really a C library error (invalid file handle).
|
||||||
|
We set the Win32 error to the closes one matching. */
|
||||||
|
SetLastError(ERROR_INVALID_HANDLE);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(result, 0, sizeof(*result));
|
memset(result, 0, sizeof(*result));
|
||||||
|
@ -649,7 +653,6 @@ _Py_fstat(int fd, struct _Py_stat_struct *result)
|
||||||
if (type == FILE_TYPE_UNKNOWN) {
|
if (type == FILE_TYPE_UNKNOWN) {
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* else: valid but unknown file */
|
/* else: valid but unknown file */
|
||||||
|
@ -664,7 +667,6 @@ _Py_fstat(int fd, struct _Py_stat_struct *result)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFileInformationByHandle(h, &info)) {
|
if (!GetFileInformationByHandle(h, &info)) {
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue