From e57fc6bbb2e98f9ef3336db698dc7dd260dfc502 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 9 Feb 2001 23:06:54 +0000 Subject: Use __environ instead of the GNU extension environ. -Erik --- libc/stdlib/getenv.c | 7 +++---- libc/stdlib/putenv.c | 21 ++++++++++----------- libc/stdlib/setenv.c | 3 --- libc/unistd/execl.c | 4 +--- libc/unistd/execlp.c | 3 +-- libc/unistd/execv.c | 5 +---- libc/unistd/execvp.c | 4 +--- 7 files changed, 17 insertions(+), 30 deletions(-) diff --git a/libc/stdlib/getenv.c b/libc/stdlib/getenv.c index b5d4de9aa..ca50402b9 100644 --- a/libc/stdlib/getenv.c +++ b/libc/stdlib/getenv.c @@ -4,10 +4,9 @@ */ #include #include +#include #include -extern char **environ; - char *getenv(var) const char *var; { @@ -16,10 +15,10 @@ const char *var; len = strlen(var); - if (!environ) + if (!__environ) return 0; - for (p = environ; *p; p++) { + for (p = __environ; *p; p++) { if (memcmp(var, *p, len) == 0 && (*p)[len] == '=') return *p + len + 1; } 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 #include +#include #include -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); diff --git a/libc/stdlib/setenv.c b/libc/stdlib/setenv.c index 6628e4cc7..a027ced96 100644 --- a/libc/stdlib/setenv.c +++ b/libc/stdlib/setenv.c @@ -21,9 +21,6 @@ Cambridge, MA 02139, USA. */ #include #include -#if !defined(HAVE_GNU_LD) && !defined (__ELF__) -#define __environ environ -#endif #if defined(_REENTRENT) || defined(_THREAD_SAFE) # include diff --git a/libc/unistd/execl.c b/libc/unistd/execl.c index 531c2ee60..a05867ef8 100644 --- a/libc/unistd/execl.c +++ b/libc/unistd/execl.c @@ -3,8 +3,6 @@ #include #include -extern char **environ; - int execl(__const char *path, __const char *arg, ...) { const char *shortargv[16]; @@ -42,7 +40,7 @@ int execl(__const char *path, __const char *arg, ...) va_end(args); - i = execve(path, (char *const *) argv, environ); + i = execve(path, (char *const *) argv, __environ); if (argv != shortargv) free(argv); diff --git a/libc/unistd/execlp.c b/libc/unistd/execlp.c index 50fb4a032..fef10d376 100644 --- a/libc/unistd/execlp.c +++ b/libc/unistd/execlp.c @@ -3,7 +3,6 @@ #include #include -extern char **environ; extern int execvep(const char *path, char *__const argv[], char *__const envp[]); int execlp(__const char *file, __const char *arg, ...) @@ -43,7 +42,7 @@ int execlp(__const char *file, __const char *arg, ...) va_end(args); - i = execvep(file, (char *const *) argv, environ); + i = execvep(file, (char *const *) argv, __environ); if (argv != shortargv) free(argv); diff --git a/libc/unistd/execv.c b/libc/unistd/execv.c index 6c8ba0d97..486f53745 100644 --- a/libc/unistd/execv.c +++ b/libc/unistd/execv.c @@ -1,9 +1,6 @@ - #include -extern char **environ; - int execv(__const char *path, char *__const argv[]) { - return execve(path, argv, environ); + return execve(path, argv, __environ); } diff --git a/libc/unistd/execvp.c b/libc/unistd/execvp.c index 943303332..e7e496063 100644 --- a/libc/unistd/execvp.c +++ b/libc/unistd/execvp.c @@ -1,10 +1,8 @@ - #include -extern char **environ; extern int execvep(const char *path, char *__const argv[], char *__const envp[]); int execvp(__const char *path, char *__const argv[]) { - return execvep(path, argv, environ); + return execvep(path, argv, __environ); } -- cgit v1.2.3