From bd5a16d2139d9ea5e9f3b2405a5dd727ba6ebccb Mon Sep 17 00:00:00 2001 From: axel Date: Sun, 28 Jan 2007 02:59:11 +1000 Subject: [PATCH] Add support for using __environ instead of environ, if it exists and environ isn't set darcs-hash:20070127165911-ac50b-72747760d767a6918152c2e4f254febb19ab1205.gz --- configure.ac | 25 +++++++++++++++++++++++++ env.c | 15 ++++++++------- fallback.c | 6 ++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 3abe2666e..76ef63c4c 100644 --- a/configure.ac +++ b/configure.ac @@ -751,6 +751,31 @@ else AC_MSG_RESULT(no) fi +# Check for __environ symbol +AC_MSG_CHECKING([for __environ symbol]) +AC_TRY_LINK( + [ + #include + ], + [ + extern char **__environ; + char **tmp = __environ; + exit(tmp!=0); + ], + have___environ=yes, + have___environ=no +) +if test "$have___environ" = yes; then + AC_MSG_RESULT(yes) + AC_DEFINE( + [HAVE___ENVIRON], + [1], + [Define to 1 if the __environ symbol is exported.] + ) +else + AC_MSG_RESULT(no) +fi + # Check if getopt_long exists and works AC_MSG_CHECKING([if getopt_long exists and works]) AC_TRY_LINK( diff --git a/env.c b/env.c index 4944729ce..5534ca308 100644 --- a/env.c +++ b/env.c @@ -1,7 +1,6 @@ /** \file env.c Functions for setting and getting environment variables. */ - #include "config.h" #include @@ -67,9 +66,13 @@ #define ENV_NULL L"\x1d" /** - At init, we read all the environment variables from this array + At init, we read all the environment variables from this array. */ extern char **environ; +/** + This should be the same thing as \c environ, but it is possible only one of the two work... +*/ +extern char **__environ; /** @@ -511,7 +514,6 @@ void env_init() wchar_t *uname; wchar_t *version; - sb_init( &dyn_var ); b_init( &export_buffer ); @@ -553,7 +555,7 @@ void env_init() hash_init( &top->env, &hash_wcs_func, &hash_wcs_cmp ); global_env = top; global = &top->env; - + /* Now the environemnt variable handling is set up, the next step is to insert valid data @@ -562,7 +564,7 @@ void env_init() /* Import environment variables */ - for( p=environ; *p; p++ ) + for( p=environ?environ:__environ; p && *p; p++ ) { wchar_t *key, *val; wchar_t *pos; @@ -575,7 +577,6 @@ void env_init() } val = wcschr( key, L'=' ); - if( val == 0 ) { @@ -600,7 +601,7 @@ void env_init() } free(key); } - + /* Set up the PATH variable */ diff --git a/fallback.c b/fallback.c index f6ce7e6fc..4e690a779 100644 --- a/fallback.c +++ b/fallback.c @@ -47,6 +47,12 @@ #include "util.h" +#ifndef HAVE___ENVIRON + +char **__environ = 0; + +#endif + #ifdef TPUTS_KLUDGE int tputs(const char *str, int affcnt, int (*fish_putc)(tputs_arg_t))