From: Guido van Rossum Date: Mon, 15 Sep 1997 22:54:34 +0000 (+0000) Subject: Add strerror() interface. X-Git-Tag: v1.5a4~157 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6a47162989ef02d627308838a12092fd6e050b8;p=python Add strerror() interface. --- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 5e247628d7..3069d34be7 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2006,7 +2006,7 @@ static char posix_putenv__doc__[] = Change or add an environment variable."; static PyObject * -posix_putenv(self,args) +posix_putenv(self, args) PyObject *self; PyObject *args; { @@ -2026,7 +2026,32 @@ posix_putenv(self,args) Py_INCREF(Py_None); return Py_None; } -#endif +#endif /* putenv */ + +#ifdef HAVE_STRERROR +static char posix_strerror__doc__[] = +"strerror(code) -> string\n\ +Translate an error code to a message string."; + +PyObject * +posix_strerror(self, args) + PyObject *self; + PyObject *args; +{ + int code; + char *message; + if (!PyArg_ParseTuple(args, "i", &code)) + return NULL; + message = strerror(code); + if (message == NULL) { + PyErr_SetString(PyExc_ValueError, + "strerror code out of range"); + return NULL; + } + return PyString_FromString(message); +} +#endif /* strerror */ + static PyMethodDef posix_methods[] = { {"chdir", posix_chdir, 0, posix_chdir__doc__}, @@ -2151,6 +2176,9 @@ static PyMethodDef posix_methods[] = { #endif #ifdef HAVE_PUTENV {"putenv", posix_putenv, 1, posix_putenv__doc__}, +#endif +#ifdef HAVE_STRERROR + {"strerror", posix_strerror, 1, posix_strerror__doc__}, #endif {NULL, NULL} /* Sentinel */ };