* environ.cc: Use new definition of "environ" throughout.

(environ_init): Explicitly initialize __cygwin_environ.
(cur_environ): New function.  Detects when user has updated their environment.
* exec.cc: Use 'environ' define throughout rather than __cygwin_environ.
* spawn.cc: Ditto.
* winsup.h: Declare cur_environ, main_environ, environ.
This commit is contained in:
Christopher Faylor
2000-07-16 20:06:11 +00:00
parent b4e59f5f14
commit 0763ee9d83
5 changed files with 42 additions and 17 deletions

View File

@@ -13,8 +13,6 @@ details. */
#include <ctype.h>
#include <fcntl.h>
#define environ __cygwin_environ
extern BOOL allow_glob;
extern BOOL allow_ntea;
extern BOOL strip_title_path;
@@ -228,7 +226,7 @@ setenv (const char *name, const char *value, int rewrite)
for (P = environ, cnt = 0; *P; ++P, ++cnt)
;
environ = (char **) realloc ((char *) environ,
__cygwin_environ = (char **) realloc ((char *) environ,
(size_t) (sizeof (char *) * (cnt + 2)));
if (!environ)
return -1;
@@ -503,7 +501,7 @@ environ_init (int already_posix)
if (!sawTERM)
envp[i++] = strdup ("TERM=cygwin");
envp[i] = NULL;
environ = envp;
__cygwin_environ = envp;
update_envptrs ();
FreeEnvironmentStringsA ((char *) rawenv);
parse_options (NULL);
@@ -580,3 +578,19 @@ winenv (const char * const *envp, int keep_posix)
return envblock;
}
/* This idiocy is necessary because the early implementers of cygwin
did not seem to know about importing data variables from the DLL.
So, we have to synchronize cygwin's idea of the environment with the
main program's with each reference to the environment. */
char ** __stdcall
cur_environ ()
{
if (*main_environ != __cygwin_environ)
{
__cygwin_environ = *main_environ;
update_envptrs ();
}
return __cygwin_environ;
}