Kaydet (Commit) f1af3fe8 authored tarafından Guido van Rossum's avatar Guido van Rossum

Added simple-minded (i.e. leaking :-) putenv() interface, if os has it.

üst 761f7922
...@@ -1596,6 +1596,30 @@ posix_ftruncate(self, args) ...@@ -1596,6 +1596,30 @@ posix_ftruncate(self, args)
} }
#endif #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[] = { static struct methodlist posix_methods[] = {
{"chdir", posix_chdir}, {"chdir", posix_chdir},
{"chmod", posix_chmod}, {"chmod", posix_chmod},
...@@ -1716,6 +1740,9 @@ static struct methodlist posix_methods[] = { ...@@ -1716,6 +1740,9 @@ static struct methodlist posix_methods[] = {
#endif #endif
#ifdef HAVE_FTRUNCATE #ifdef HAVE_FTRUNCATE
{"ftruncate", posix_ftruncate, 1}, {"ftruncate", posix_ftruncate, 1},
#endif
#ifdef HAVE_PUTENV
{"putenv", posix_putenv, 1},
#endif #endif
{NULL, NULL} /* Sentinel */ {NULL, NULL} /* Sentinel */
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment