summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-07-23 19:18:10 (GMT)
committerGuido van Rossum <guido@python.org>1996-07-23 19:18:10 (GMT)
commitf1af3fe8ebcb506cd78e907d48fbf8f4868164d8 (patch)
tree2d232a33ecff54006f75998cc11960d11120101b /Modules/posixmodule.c
parent761f7922ada0f4e398d3b539b9cfb1a403d7f581 (diff)
downloadcpython-f1af3fe8ebcb506cd78e907d48fbf8f4868164d8.zip
cpython-f1af3fe8ebcb506cd78e907d48fbf8f4868164d8.tar.gz
cpython-f1af3fe8ebcb506cd78e907d48fbf8f4868164d8.tar.bz2
Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e843cfe..8e56661 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1596,6 +1596,30 @@ posix_ftruncate(self, args)
}
#endif
+#ifdef HAVE_PUTENV
+static object *
+posix_putenv(self,args)
+ object *self;
+ object *args;
+{
+ char *s1, *s2;
+ char *new;
+
+ if (!newgetargs(args, "ss", &s1, &s2))
+ return NULL;
+ /* XXX This leaks memory -- not easy to fix :-( */
+ if ((new = malloc(strlen(s1) + strlen(s2) + 2)) == NULL)
+ return err_nomem();
+ (void) sprintf(new, "%s=%s", s1, s2);
+ if (putenv(new)) {
+ posix_error();
+ return NULL;
+ }
+ INCREF(None);
+ return None;
+}
+#endif
+
static struct methodlist posix_methods[] = {
{"chdir", posix_chdir},
{"chmod", posix_chmod},
@@ -1717,6 +1741,9 @@ static struct methodlist posix_methods[] = {
#ifdef HAVE_FTRUNCATE
{"ftruncate", posix_ftruncate, 1},
#endif
+#ifdef HAVE_PUTENV
+ {"putenv", posix_putenv, 1},
+#endif
{NULL, NULL} /* Sentinel */
};