summaryrefslogtreecommitdiff
path: root/lib/putenv.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2013-02-18 18:48:48 +0100
committerAndy Wingo <wingo@pobox.com>2013-02-18 18:48:48 +0100
commitaf07e10429c1513c2348289888b240926264b32b (patch)
treea05b78ee58618c46efa4c03da362dad3c2d8eb2b /lib/putenv.c
parent739941679c2c7dc36c29c30aff7d4c1b436ba773 (diff)
downloadguile-af07e10429c1513c2348289888b240926264b32b.tar.gz
Update to gnulib 0.0.7865-a828.
Diffstat (limited to 'lib/putenv.c')
-rw-r--r--lib/putenv.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/putenv.c b/lib/putenv.c
index eb3fae375..2abc6acff 100644
--- a/lib/putenv.c
+++ b/lib/putenv.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1994, 1997-1998, 2000, 2003-2012 Free Software
+/* Copyright (C) 1991, 1994, 1997-1998, 2000, 2003-2013 Free Software
Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C
@@ -115,6 +115,37 @@ putenv (char *string)
if (*ep == NULL)
{
+#if HAVE__PUTENV
+ /* Rely on _putenv to allocate the new environment. If other
+ parts of the application use _putenv, the !HAVE__PUTENV code
+ would fight over who owns the environ vector, causing a crash. */
+ if (name_end[1])
+ return _putenv (string);
+ else
+ {
+ /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME=x")
+ to allocate the environ vector and then replace the new
+ entry with "NAME=". */
+ int putenv_result, putenv_errno;
+ char *name_x = malloc (name_end - string + sizeof "=x");
+ if (!name_x)
+ return -1;
+ memcpy (name_x, string, name_end - string + 1);
+ name_x[name_end - string + 1] = 'x';
+ name_x[name_end - string + 2] = 0;
+ putenv_result = _putenv (name_x);
+ putenv_errno = errno;
+ for (ep = environ; *ep; ep++)
+ if (*ep == name_x)
+ {
+ *ep = string;
+ break;
+ }
+ free (name_x);
+ __set_errno (putenv_errno);
+ return putenv_result;
+ }
+#else
static char **last_environ = NULL;
char **new_environ = (char **) malloc ((size + 2) * sizeof (char *));
if (new_environ == NULL)
@@ -126,6 +157,7 @@ putenv (char *string)
free (last_environ);
last_environ = new_environ;
environ = new_environ;
+#endif
}
else
*ep = string;