Kaynağa Gözat

consistently use the internal name __environ for environ

patch by Jens Gustedt.
previously, the intended policy was to use __environ in code that must
conform to the ISO C namespace requirements, and environ elsewhere.
this policy was not followed in practice anyway, making things
confusing. on top of that, Jens reported that certain combinations of
link-time optimization options were breaking with the inconsistent
references; this seems to be a compiler or linker bug, but having it
go away is a nice side effect of the changes made here.
Rich Felker 12 yıl önce
ebeveyn
işleme
23ccb80fcb
3 değiştirilmiş dosya ile 4 ekleme ve 5 silme
  1. 0 1
      src/internal/libc.h
  2. 2 2
      src/process/execvp.c
  3. 2 2
      src/process/system.c

+ 0 - 1
src/internal/libc.h

@@ -57,7 +57,6 @@ void __synccall(void (*)(void *), void *);
 int __setxid(int, int, int, int);
 
 extern char **__environ;
-#define environ __environ
 
 #undef weak_alias
 #define weak_alias(old, new) \

+ 2 - 2
src/process/execvp.c

@@ -4,7 +4,7 @@
 #include <errno.h>
 #include <limits.h>
 
-extern char **environ;
+extern char **__environ;
 
 int __execvpe(const char *file, char *const argv[], char *const envp[])
 {
@@ -45,5 +45,5 @@ int __execvpe(const char *file, char *const argv[], char *const envp[])
 
 int execvp(const char *file, char *const argv[])
 {
-	return __execvpe(file, argv, environ);
+	return __execvpe(file, argv, __environ);
 }

+ 2 - 2
src/process/system.c

@@ -13,7 +13,7 @@ static void dummy_0()
 weak_alias(dummy_0, __acquire_ptc);
 weak_alias(dummy_0, __release_ptc);
 
-extern char **environ;
+extern char **__environ;
 
 int system(const char *cmd)
 {
@@ -40,7 +40,7 @@ int system(const char *cmd)
 	posix_spawnattr_setsigdefault(&attr, &reset);
 	posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
 	ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
-		(char *[]){"sh", "-c", (char *)cmd, 0}, environ);
+		(char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
 	posix_spawnattr_destroy(&attr);
 
 	if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR);