summaryrefslogtreecommitdiffstats
path: root/Objects/fileobject.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-11-09 16:17:24 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-11-09 16:17:24 (GMT)
commit41c8321252a84d8a9d0ded374e7db7a4393036be (patch)
treed2e2f9c274be1c8b1e84b23863c9bda799356cb6 /Objects/fileobject.c
parent20747fa167dc8224c01ab0ab2ece81c9c5927dec (diff)
downloadcpython-41c8321252a84d8a9d0ded374e7db7a4393036be.zip
cpython-41c8321252a84d8a9d0ded374e7db7a4393036be.tar.gz
cpython-41c8321252a84d8a9d0ded374e7db7a4393036be.tar.bz2
Fix SF buf #476953: Bad more for opening file gives bad msg.
If fopen() fails with EINVAL it means that the mode argument is invalid. Return the mode in the error message instead of the filename.
Diffstat (limited to 'Objects/fileobject.c')
-rw-r--r--Objects/fileobject.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index ebccc84..9284185 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -121,13 +121,17 @@ open_the_file(PyFileObject *f, char *name, char *mode)
if (f->f_fp == NULL) {
#ifdef NO_FOPEN_ERRNO
/* Metroworks only, not testable, so unchanged */
- if ( errno == 0 ) {
+ if (errno == 0) {
PyErr_SetString(PyExc_IOError, "Cannot open file");
Py_DECREF(f);
return NULL;
}
#endif
- PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
+ if (errno == EINVAL)
+ PyErr_Format(PyExc_IOError, "invalid argument: %s",
+ mode);
+ else
+ PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);
f = NULL;
}
return (PyObject *)f;