summaryrefslogtreecommitdiff
path: root/libc/stdlib/putenv.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2002-05-30 23:49:43 +0000
committerEric Andersen <andersen@codepoet.org>2002-05-30 23:49:43 +0000
commitad28b52f542ff06c24f05d04b33707cefced9ea5 (patch)
tree24c74619426601381c6f6be828a0bd5b4f0025be /libc/stdlib/putenv.c
parentaf562a23724d27b16c4872590886c96554bba68a (diff)
Rework setenv, getenv and friends per the latest glibc code, but cleaned
up for readability. Merge in putenv. Add clearenv as a side effect. -Erik
Diffstat (limited to 'libc/stdlib/putenv.c')
-rw-r--r--libc/stdlib/putenv.c65
1 files changed, 0 insertions, 65 deletions
diff --git a/libc/stdlib/putenv.c b/libc/stdlib/putenv.c
deleted file mode 100644
index b5a202bfd..000000000
--- a/libc/stdlib/putenv.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
- * This file is part of the Linux-8086 C library and is distributed
- * under the GNU Library General Public License.
- */
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <malloc.h>
-
-#define ADD_NUM 4
-
-int putenv (char *var)
-{
- static char **mall_env = 0;
- static int extras = 0;
- char **p, **d;
- char *r;
- int len;
-
- r = strchr(var, '=');
- if (r == 0)
- len = strlen(var);
- else
- len = r - var;
-
- if (!__environ) {
- __environ = (char **) malloc(ADD_NUM * sizeof(char *));
- memset(__environ, 0, sizeof(char *) * ADD_NUM);
-
- extras = ADD_NUM;
- }
-
- for (p = __environ; *p; p++) {
- if (memcmp(var, *p, len) == 0 && (*p)[len] == '=') {
- while ((p[0] = p[1]))
- p++;
- extras++;
- break;
- }
- }
- if (r == 0)
- return 0;
- if (extras <= 0) { /* Need more space */
- d = malloc((p - __environ + 1 + ADD_NUM) * sizeof(char *));
-
- if (d == 0)
- return -1;
-
- memcpy((void *) d, (void *) __environ,
-
- (p - __environ + 1) * sizeof(char *));
- p = d + (p - __environ);
- extras = ADD_NUM;
-
- if (mall_env)
- free(mall_env);
- __environ = d;
- mall_env = d;
- }
- *p++ = strdup((char *) var);
- *p = '\0';
- extras--;
-
- return 0;
-}