Use _doserrno

This commit is contained in:
Zackery Spytz 2020-06-13 21:10:10 -06:00
parent 48d7a3e7e3
commit 0580ee300a
2 changed files with 9 additions and 5 deletions

View File

@ -370,6 +370,9 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
}
errno = 0;
#ifdef MS_WINDOWS
_doserrno = 0;
#endif
if (opener == Py_None) {
do {
Py_BEGIN_ALLOW_THREADS
@ -418,7 +421,12 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
fd_is_own = 1;
if (self->fd < 0) {
#ifdef MS_WINDOWS
PyErr_SetExcFromWindowsErrWithFilenameObject(
PyExc_OSError, _doserrno, nameobj);
#else
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, nameobj);
#endif
goto error;
}

View File

@ -700,11 +700,7 @@ PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, P
table, we use it, otherwise we assume it really _is_
a Win32 error code
*/
if (i == ENOENT && GetLastError() == ERROR_PATH_NOT_FOUND) {
message = PyUnicode_FromString("No such path or path exceeds "
"maximum allowed length");
}
else if (i > 0 && i < _sys_nerr) {
if (i > 0 && i < _sys_nerr) {
message = PyUnicode_FromString(_sys_errlist[i]);
}
else {