comparison lib/putenv.c @ 17370:2a9ec0103b3c

putenv: port to Solaris 10 * lib/putenv.c (_unsetenv, putenv): Use HAVE_DECL__PUTENV, not HAVE__PUTENV. Solaris 10 has a _putenv that's not declared and is not what is wanted here. * m4/putenv.m4 (gl_PREREQ_PUTENV): Check for _putenv's declaration, not for its existence.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 13 Mar 2013 00:10:30 -0700
parents a154fccd3b21
children
comparison
equal deleted inserted replaced
17369:a4a11de07980 17370:2a9ec0103b3c
60 60
61 static int 61 static int
62 _unsetenv (const char *name) 62 _unsetenv (const char *name)
63 { 63 {
64 size_t len; 64 size_t len;
65 #if !HAVE__PUTENV 65 #if !HAVE_DECL__PUTENV
66 char **ep; 66 char **ep;
67 #endif 67 #endif
68 68
69 if (name == NULL || *name == '\0' || strchr (name, '=') != NULL) 69 if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
70 { 70 {
72 return -1; 72 return -1;
73 } 73 }
74 74
75 len = strlen (name); 75 len = strlen (name);
76 76
77 #if HAVE__PUTENV 77 #if HAVE_DECL__PUTENV
78 { 78 {
79 int putenv_result, putenv_errno; 79 int putenv_result, putenv_errno;
80 char *name_ = malloc (len + 2); 80 char *name_ = malloc (len + 2);
81 memcpy (name_, name, len); 81 memcpy (name_, name, len);
82 name_[len] = '='; 82 name_[len] = '=';
125 { 125 {
126 /* Remove the variable from the environment. */ 126 /* Remove the variable from the environment. */
127 return _unsetenv (string); 127 return _unsetenv (string);
128 } 128 }
129 129
130 #if HAVE__PUTENV 130 #if HAVE_DECL__PUTENV
131 /* Rely on _putenv to allocate the new environment. If other 131 /* Rely on _putenv to allocate the new environment. If other
132 parts of the application use _putenv, the !HAVE__PUTENV code 132 parts of the application use _putenv, the !HAVE_DECL__PUTENV code
133 would fight over who owns the environ vector, causing a crash. */ 133 would fight over who owns the environ vector, causing a crash. */
134 if (name_end[1]) 134 if (name_end[1])
135 return _putenv (string); 135 return _putenv (string);
136 else 136 else
137 { 137 {
186 memcpy (new_environ + 1, environ, (size + 1) * sizeof *new_environ); 186 memcpy (new_environ + 1, environ, (size + 1) * sizeof *new_environ);
187 free (last_environ); 187 free (last_environ);
188 last_environ = new_environ; 188 last_environ = new_environ;
189 environ = new_environ; 189 environ = new_environ;
190 } 190 }
191 #endif
192 191
193 return 0; 192 return 0;
193 #endif
194 } 194 }