summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-09-15 22:54:34 (GMT)
committerGuido van Rossum <guido@python.org>1997-09-15 22:54:34 (GMT)
commitb6a47162989ef02d627308838a12092fd6e050b8 (patch)
tree95749b0bf6e7bfdc1546e5a438a27ba1a939103d /Modules
parenta2f626ff5826b420a306b341df52f9546d1f71f4 (diff)
downloadcpython-b6a47162989ef02d627308838a12092fd6e050b8.zip
cpython-b6a47162989ef02d627308838a12092fd6e050b8.tar.gz
cpython-b6a47162989ef02d627308838a12092fd6e050b8.tar.bz2
Add strerror() interface.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 5e24762..3069d34 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__},
@@ -2152,6 +2177,9 @@ static PyMethodDef posix_methods[] = {
#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 */
};