summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-09-17 09:34:06 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-09-17 09:34:06 (GMT)
commit29275c9331873900af43c6c817234fcdd358a659 (patch)
tree28735e9b9a4a4f7a62bae76cb3b4a3c58cfe1939 /Modules
parentceb7c18c109bff48d5c3327c0ed9209b68540655 (diff)
downloadcpython-29275c9331873900af43c6c817234fcdd358a659.zip
cpython-29275c9331873900af43c6c817234fcdd358a659.tar.gz
cpython-29275c9331873900af43c6c817234fcdd358a659.tar.bz2
Deal with NULL fields in mkpwent.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/pwdmodule.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index cb139bb..9134edc 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -44,6 +44,17 @@ exception is raised if the entry asked for cannot be found.");
static PyTypeObject StructPwdType;
+static void
+sets(PyObject *v, int i, char* val)
+{
+ if (val)
+ PyStructSequence_SET_ITEM(v, i, PyString_FromString(val));
+ else {
+ PyStructSequence_SET_ITEM(v, i, Py_None);
+ Py_INCREF(Py_None);
+ }
+}
+
static PyObject *
mkpwent(struct passwd *p)
{
@@ -53,7 +64,7 @@ mkpwent(struct passwd *p)
return NULL;
#define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyInt_FromLong((long) val))
-#define SETS(i,val) PyStructSequence_SET_ITEM(v, i, PyString_FromString(val))
+#define SETS(i,val) sets(v, i, val)
SETS(setIndex++, p->pw_name);
SETS(setIndex++, p->pw_passwd);