/* Set a POSIX-specific error from errno, and return NULL */
-static PyObject * posix_error()
+static PyObject *
+posix_error()
{
return PyErr_SetFromErrno(PosixError);
}
+static PyObject *
+posix_error_with_filename(name)
+ char* name;
+{
+ return PyErr_SetFromErrnoWithFilename(PosixError, name);
+}
+
#if defined(PYOS_OS2)
/**********************************************************************
res = (*func)(path1);
Py_END_ALLOW_THREADS
if (res < 0)
- return posix_error();
+ return posix_error_with_filename(path1);
Py_INCREF(Py_None);
return Py_None;
}
res = (*func)(path1, path2);
Py_END_ALLOW_THREADS
if (res != 0)
+ /* XXX how to report both path1 and path2??? */
return posix_error();
Py_INCREF(Py_None);
return Py_None;
res = (*func)(path, i);
Py_END_ALLOW_THREADS
if (res < 0)
- return posix_error();
+ return posix_error_with_filename(path);
Py_INCREF(Py_None);
return Py_None;
}
res = (*func)(path, i, i2);
Py_END_ALLOW_THREADS
if (res < 0)
- return posix_error();
+ return posix_error_with_filename(path);
Py_INCREF(Py_None);
return Py_None;
}
res = (*statfunc)(path, &st);
Py_END_ALLOW_THREADS
if (res != 0)
- return posix_error();
+ return posix_error_with_filename(path);
return Py_BuildValue("(llllllllll)",
(long)st.st_mode,
(long)st.st_ino,
#endif
Py_END_ALLOW_THREADS
if (res < 0)
- return posix_error();
+ return posix_error_with_filename(path);
Py_INCREF(Py_None);
return Py_None;
}
res = utime(path, UTIME_ARG);
Py_END_ALLOW_THREADS
if (res < 0)
- return posix_error();
+ return posix_error_with_filename(path);
Py_INCREF(Py_None);
return Py_None;
#undef UTIME_ARG
n = readlink(path, buf, (int) sizeof buf);
Py_END_ALLOW_THREADS
if (n < 0)
- return posix_error();
+ return posix_error_with_filename(path);
return PyString_FromStringAndSize(buf, n);
}
#endif /* HAVE_READLINK */
fd = open(file, flag, mode);
Py_END_ALLOW_THREADS
if (fd < 0)
- return posix_error();
+ return posix_error_with_filename(file);
return PyInt_FromLong((long)fd);
}
if (all_ins(d))
return;
- /* Initialize exception */
- PosixError = PyErr_NewException("os.error", NULL, NULL);
- if (PosixError != NULL)
- PyDict_SetItemString(d, "error", PosixError);
+ Py_INCREF(PyExc_OSError);
+ PosixError = PyExc_OSError;
+ PyDict_SetItemString(d, "error", PosixError);
}