]> granicus.if.org Git - python/commitdiff
When errno is zero, avoid calling strerror() and use "Error" for the
authorGuido van Rossum <guido@python.org>
Wed, 14 Oct 1998 20:38:13 +0000 (20:38 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 14 Oct 1998 20:38:13 +0000 (20:38 +0000)
message.

Python/errors.c

index c0efbf1b2657dee61b2cbfaeb950e3868623b97b..423f792538cdddb05f922e5386e8f7bb67729e93 100644 (file)
@@ -282,15 +282,20 @@ PyErr_SetFromErrnoWithFilename(exc, filename)
        char *filename;
 {
        PyObject *v;
+       char *s;
        int i = errno;
 #ifdef EINTR
        if (i == EINTR && PyErr_CheckSignals())
                return NULL;
 #endif
+       if (i == 0)
+               s = "Error"; /* Sometimes errno didn't get set */
+       else
+               s = strerror(i);
        if (filename != NULL && Py_UseClassExceptionsFlag)
-               v = Py_BuildValue("(iss)", i, strerror(i), filename);
+               v = Py_BuildValue("(iss)", i, s, filename);
        else
-               v = Py_BuildValue("(is)", i, strerror(i));
+               v = Py_BuildValue("(is)", i, s);
        if (v != NULL) {
                PyErr_SetObject(exc, v);
                Py_DECREF(v);