aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--configure.ac25
-rw-r--r--env.c15
-rw-r--r--fallback.c6
3 files changed, 39 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index 3abe2666..76ef63c4 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 <unistd.h>
+ ],
+ [
+ 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 4944729c..5534ca30 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 <stdlib.h>
@@ -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 f6ce7e6f..4e690a77 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))