summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 22f70b1..65e09c0 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4083,6 +4083,37 @@ posix_putenv(PyObject *self, PyObject *args)
}
#endif /* putenv */
+#ifdef HAVE_UNSETENV
+static char posix_unsetenv__doc__[] =
+"unsetenv(key) -> None\n\
+Delete an environment variable.";
+
+static PyObject *
+posix_unsetenv(PyObject *self, PyObject *args)
+{
+ char *s1;
+
+ if (!PyArg_ParseTuple(args, "s:unsetenv", &s1))
+ return NULL;
+
+ unsetenv(s1);
+
+ /* Remove the key from posix_putenv_garbage;
+ * this will cause it to be collected. This has to
+ * happen after the real unsetenv() call because the
+ * old value was still accessible until then.
+ */
+ if (PyDict_DelItem(posix_putenv_garbage,
+ PyTuple_GET_ITEM(args, 0))) {
+ /* really not much we can do; just leak */
+ PyErr_Clear();
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+#endif /* unsetenv */
+
#ifdef HAVE_STRERROR
static char posix_strerror__doc__[] =
"strerror(code) -> string\n\
@@ -5667,6 +5698,9 @@ static PyMethodDef posix_methods[] = {
#ifdef HAVE_PUTENV
{"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__},
#endif
+#ifdef HAVE_UNSETENV
+ {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__},
+#endif
#ifdef HAVE_STRERROR
{"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__},
#endif