summaryrefslogtreecommitdiff
path: root/libc/stdlib/putenv.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-02-09 23:06:54 +0000
committerEric Andersen <andersen@codepoet.org>2001-02-09 23:06:54 +0000
commite57fc6bbb2e98f9ef3336db698dc7dd260dfc502 (patch)
treed525aa4fb8a13d6459c6339e4543c840b415e636 /libc/stdlib/putenv.c
parent56139d5a7109db33a7f3e951595a45a0f7f12cd4 (diff)
Use __environ instead of the GNU extension environ.
-Erik
Diffstat (limited to 'libc/stdlib/putenv.c')
-rw-r--r--libc/stdlib/putenv.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/libc/stdlib/putenv.c b/libc/stdlib/putenv.c
index 5b2ebcb3c..5f27e57d7 100644
--- a/libc/stdlib/putenv.c
+++ b/libc/stdlib/putenv.c
@@ -4,10 +4,9 @@
*/
#include <string.h>
#include <stdlib.h>
+#include <unistd.h>
#include <malloc.h>
-extern char **environ;
-
#define ADD_NUM 4
int putenv(var)
@@ -25,14 +24,14 @@ const char *var;
else
len = r - var;
- if (!environ) {
- environ = (char **) malloc(ADD_NUM * sizeof(char *));
- memset(environ, 0, sizeof(char *) * ADD_NUM);
+ if (!__environ) {
+ __environ = (char **) malloc(ADD_NUM * sizeof(char *));
+ memset(__environ, 0, sizeof(char *) * ADD_NUM);
extras = ADD_NUM;
}
- for (p = environ; *p; p++) {
+ for (p = __environ; *p; p++) {
if (memcmp(var, *p, len) == 0 && (*p)[len] == '=') {
while ((p[0] = p[1]))
p++;
@@ -43,20 +42,20 @@ const char *var;
if (r == 0)
return 0;
if (extras <= 0) { /* Need more space */
- d = malloc((p - environ + 1 + ADD_NUM) * sizeof(char *));
+ d = malloc((p - __environ + 1 + ADD_NUM) * sizeof(char *));
if (d == 0)
return -1;
- memcpy((void *) d, (void *) environ,
+ memcpy((void *) d, (void *) __environ,
- (p - environ + 1) * sizeof(char *));
- p = d + (p - environ);
+ (p - __environ + 1) * sizeof(char *));
+ p = d + (p - __environ);
extras = ADD_NUM;
if (mall_env)
free(mall_env);
- environ = d;
+ __environ = d;
mall_env = d;
}
*p++ = strdup((char *) var);