return PyErr_SetFromWindowsErr(errno);
}
-static PyObject *
-win32_error_unicode(char* function, wchar_t* filename)
-{
- /* XXX - see win32_error for comments on 'function' */
- errno = GetLastError();
- if (filename)
- return PyErr_SetFromWindowsErrWithUnicodeFilename(errno, filename);
- else
- return PyErr_SetFromWindowsErr(errno);
-}
-
static PyObject *
win32_error_object(char* function, PyObject* filename)
{
#ifdef MS_WINDOWS
-static PyObject*
-win32_1str(PyObject* args, char* func,
- char* format, BOOL (__stdcall *funcA)(LPCSTR),
- char* wformat, BOOL (__stdcall *funcW)(LPWSTR))
-{
- PyObject *uni;
- const char *ansi;
- BOOL result;
-
- if (PyArg_ParseTuple(args, wformat, &uni))
- {
- wchar_t *wstr = PyUnicode_AsUnicode(uni);
- if (wstr == NULL)
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- result = funcW(wstr);
- Py_END_ALLOW_THREADS
- if (!result)
- return win32_error_object(func, uni);
- Py_INCREF(Py_None);
- return Py_None;
- }
- PyErr_Clear();
-
- if (!PyArg_ParseTuple(args, format, &ansi))
- return NULL;
- if (win32_warn_bytes_api())
- return NULL;
- Py_BEGIN_ALLOW_THREADS
- result = funcA(ansi);
- Py_END_ALLOW_THREADS
- if (!result)
- return win32_error(func, ansi);
- Py_INCREF(Py_None);
- return Py_None;
-
-}
-
/* This is a reimplementation of the C library's chdir function,
but one that produces Win32 errors instead of DOS error codes.
chdir is essentially a wrapper around SetCurrentDirectory; however,
Py_END_ALLOW_THREADS
if (!result) {
- return_value = win32_error_object("chmod", path.object);
+ return_value = path_error(&path);
goto exit;
}
#else /* MS_WINDOWS */
return NULL;
}
if (!len) {
- if (wbuf2 != wbuf) free(wbuf2);
- return win32_error("getcwdu", NULL);
+ if (wbuf2 != wbuf)
+ free(wbuf2);
+ return PyErr_SetFromWindowsErr(0);
}
resobj = PyUnicode_FromWideChar(wbuf2, len);
- if (wbuf2 != wbuf) free(wbuf2);
+ if (wbuf2 != wbuf)
+ free(wbuf2);
return resobj;
}
Py_END_ALLOW_THREADS
if (!result) {
- return_value = win32_error_object("link", dst.object);
+ return_value = path_error(&dst);
goto exit;
}
#else
if (error == ERROR_FILE_NOT_FOUND)
goto exit;
Py_DECREF(list);
- list = NULL;
- win32_error_unicode("FindFirstFileW", wnamebuf);
+ list = path_error(&path);
goto exit;
}
do {
it got to the end of the directory. */
if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
Py_DECREF(list);
- list = win32_error_unicode("FindNextFileW", wnamebuf);
+ list = path_error(&path);
goto exit;
}
} while (result == TRUE);
if (error == ERROR_FILE_NOT_FOUND)
goto exit;
Py_DECREF(list);
- list = win32_error("FindFirstFile", namebuf);
+ path.func = "FindFirstFile";
+ list = path_error(&path);
goto exit;
}
do {
it got to the end of the directory. */
if (!result && GetLastError() != ERROR_NO_MORE_FILES) {
Py_DECREF(list);
- list = win32_error("FindNextFile", namebuf);
+ path.func = "FindNextFile";
+ list = path_error(&path);
goto exit;
}
} while (result == TRUE);
if (FindClose(hFindFile) == FALSE) {
if (list != NULL) {
Py_DECREF(list);
- list = win32_error_object("FindClose", path.object);
+ list = path_error(&path);
}
}
}
return posix_error();
if (!GetFileInformationByHandle(hFile, &info))
- return win32_error("_getfileinformation", NULL);
+ return PyErr_SetFromWindowsErr(0);
return Py_BuildValue("iii", info.dwVolumeSerialNumber,
info.nFileIndexHigh,
Py_END_ALLOW_THREADS
if (!result) {
- return_value = win32_error_object("mkdir", path.object);
+ return_value = path_error(&path);
goto exit;
}
#else
Py_END_ALLOW_THREADS
if (!result) {
- return_value = win32_error_object(function_name, dst.object);
+ return_value = path_error(&dst);
goto exit;
}
PyObject *return_value = NULL;
memset(&path, 0, sizeof(path));
+ path.function_name = "utime";
#if UTIME_HAVE_FD
path.allow_fd = 1;
#endif
FILE_FLAG_BACKUP_SEMANTICS, NULL);
Py_END_ALLOW_THREADS
if (hFile == INVALID_HANDLE_VALUE) {
- win32_error_object("utime", path.object);
+ path_error(&path);
goto exit;
}
GetSystemTime(&now);
if (!SystemTimeToFileTime(&now, &mtime) ||
!SystemTimeToFileTime(&now, &atime)) {
- win32_error("utime", NULL);
+ PyErr_SetFromWindowsErr(0);
goto exit;
}
}
as that may confuse the user into believing that
something is wrong with the file, when it also
could be the time stamp that gives a problem. */
- win32_error("utime", NULL);
+ PyErr_SetFromWindowsErr(0);
goto exit;
}
#else /* MS_WINDOWS */
Py_END_ALLOW_THREADS
if (!result) {
- return_value = win32_error_object("symlink", src.object);
+ return_value = path_error(&src);
goto exit;
}
Py_END_ALLOW_THREADS
if (res != 0) {
#ifdef MS_WINDOWS
- return win32_error("fstat", NULL);
+ return PyErr_SetFromWindowsErr(0);
#else
return posix_error();
#endif
BOOL ok;
ok = CreatePipe(&read, &write, NULL, 0);
if (!ok)
- return win32_error("CreatePipe", NULL);
+ return PyErr_SetFromWindowsErr(0);
read_fd = _open_osfhandle((Py_intptr_t)read, 0);
write_fd = _open_osfhandle((Py_intptr_t)write, 1);
return Py_BuildValue("(ii)", read_fd, write_fd);