]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF bug 538827: Python open w/ MSVC6: bad error msgs.
authorTim Peters <tim.peters@gmail.com>
Mon, 8 Apr 2002 04:19:50 +0000 (04:19 +0000)
committerTim Peters <tim.peters@gmail.com>
Mon, 8 Apr 2002 04:19:50 +0000 (04:19 +0000)
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.

Objects/fileobject.c

index 1430eef7419580913eb785845dbc15621d37a779..7ac6efbbc831c40ba53568767279baf0f9d6e826 100644 (file)
@@ -127,9 +127,22 @@ 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);