From e0e59829e006ddf670d0cbffa9b9d00b71227d70 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 14 Oct 1998 20:38:13 +0000 Subject: [PATCH] When errno is zero, avoid calling strerror() and use "Error" for the message. --- Python/errors.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Python/errors.c b/Python/errors.c index c0efbf1b265..423f792538c 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -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 (filename != NULL && Py_UseClassExceptionsFlag) - v = Py_BuildValue("(iss)", i, strerror(i), filename); + if (i == 0) + s = "Error"; /* Sometimes errno didn't get set */ else - v = Py_BuildValue("(is)", i, strerror(i)); + s = strerror(i); + if (filename != NULL && Py_UseClassExceptionsFlag) + v = Py_BuildValue("(iss)", i, s, filename); + else + v = Py_BuildValue("(is)", i, s); if (v != NULL) { PyErr_SetObject(exc, v); Py_DECREF(v);