From 94785ef14294e9d924c9ceee3d6f9082d4555f28 Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Thu, 20 Apr 2006 01:29:48 +0000 Subject: Correct implementation and documentation of os.confstr. Add a simple test case. I've yet to figure out how to provoke a None return I can test. --- Modules/posixmodule.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'Modules/posixmodule.c') diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d91d8b5eec..4c462a039c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6817,15 +6817,18 @@ posix_confstr(PyObject *self, PyObject *args) errno = 0; len = confstr(name, buffer, sizeof(buffer)); - if (len == -1) { - posix_error(); - } - else if (len == 0) { - result = PyString_FromString(""); + if (len == 0) { + if (errno) { + posix_error(); + } + else { + result = Py_None; + Py_INCREF(Py_None); + } } else { if ((unsigned int)len >= sizeof(buffer)) { - result = PyString_FromStringAndSize(NULL, len); + result = PyString_FromStringAndSize(NULL, len+1); if (result != NULL) confstr(name, PyString_AS_STRING(result), len+1); } -- cgit v1.2.1