summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2006-04-18 00:49:49 (GMT)
committerSkip Montanaro <skip@pobox.com>2006-04-18 00:49:49 (GMT)
commitdd527fcbcd484c1d4e29798c59ed45452c288eba (patch)
tree94bc3647f5e658fb68edb5565cecfd843389a279 /Modules/posixmodule.c
parent429433b30bbfb957c38b1bc0b699cda2fb30db1c (diff)
downloadcpython-dd527fcbcd484c1d4e29798c59ed45452c288eba.zip
cpython-dd527fcbcd484c1d4e29798c59ed45452c288eba.tar.gz
cpython-dd527fcbcd484c1d4e29798c59ed45452c288eba.tar.bz2
reset errno before calling confstr - use confstr() doc to simplify checks afterwards
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 53f35da..d91d8b5 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6812,17 +6812,19 @@ posix_confstr(PyObject *self, PyObject *args)
char buffer[64];
if (PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) {
- int len = confstr(name, buffer, sizeof(buffer));
+ int len;
errno = 0;
- if (len == 0) {
- if (errno != 0)
- posix_error();
- else
- result = PyString_FromString("");
+ len = confstr(name, buffer, sizeof(buffer));
+
+ if (len == -1) {
+ posix_error();
+ }
+ else if (len == 0) {
+ result = PyString_FromString("");
}
else {
- if (len >= sizeof(buffer)) {
+ if ((unsigned int)len >= sizeof(buffer)) {
result = PyString_FromStringAndSize(NULL, len);
if (result != NULL)
confstr(name, PyString_AS_STRING(result), len+1);