diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-04-08 04:13:12 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-04-08 04:13:12 (GMT) |
commit | 2ea9111cf17db465ce0a32d779dd20da87824e44 (patch) | |
tree | 30418a1f63dd8819321bd024dbf4ea1a2151b7d4 /Objects | |
parent | 0986d8250f7ae4019c3e5b5c934dc0fd55f2b8de (diff) | |
download | cpython-2ea9111cf17db465ce0a32d779dd20da87824e44.zip cpython-2ea9111cf17db465ce0a32d779dd20da87824e44.tar.gz cpython-2ea9111cf17db465ce0a32d779dd20da87824e44.tar.bz2 |
SF bug 538827: Python open w/ MSVC6: bad error msgs.
open_the_file: Some (not all) flavors of Windows set errno to EINVAL
when passed a syntactically invalid filename. Python turned that into an
incomprehensible complaint about the mode string. Fixed by special-casing
MSVC.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/fileobject.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c index a752a20..a03796b 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -150,14 +150,27 @@ open_the_file(PyFileObject *f, char *name, char *mode) return NULL; } #endif +#ifdef _MSC_VER + /* MSVC 6 (Microsoft) leaves errno at 0 for bad mode strings, + * across all Windows flavors. When it sets EINVAL varies + * across Windows flavors, the exact conditions aren't + * documented, and the answer lies in the OS's implementation + * of Win32's CreateFile function (whose source is secret). + * Seems the best we can do is map EINVAL to ENOENT. + */ + if (errno == 0) /* bad mode string */ + errno = EINVAL; + else if (errno == EINVAL) /* unknown, but not a mode string */ + errno = ENOENT; +#endif if (errno == EINVAL) - PyErr_Format(PyExc_IOError, "invalid argument: %s", + PyErr_Format(PyExc_IOError, "invalid mode: %s", mode); else PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); f = NULL; } - if (f != NULL) + if (f != NULL) f = dircheck(f); return (PyObject *)f; } |