summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/environ.cc
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/environ.cc')
-rw-r--r--winsup/cygwin/environ.cc22
1 files changed, 19 insertions, 3 deletions
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index e9c92c42e..4813e02fe 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -1071,9 +1071,11 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
sys_wcstombs_alloc (&winenv[winnum], HEAP_NOTHEAP, var);
}
DestroyEnvironmentBlock (cwinenv);
- /* Eliminate variables which are already available in envp. The windows
- env is sorted, so we can use bsearch. We're doing this first step,
- so the following code doesn't allocate too much memory. */
+ /* Eliminate variables which are already available in envp, as well as
+ the small set of crucial variables needing POSIX conversion and
+ potentially collide. The windows env is sorted, so we can use
+ bsearch. We're doing this first step, so the following code doesn't
+ allocate too much memory. */
if (winenv)
{
for (srcp = envp; *srcp; srcp++)
@@ -1091,6 +1093,20 @@ build_env (const char * const *envp, PWCHAR &envblock, int &envc,
--winnum;
}
}
+ for (char **elem = winenv; *elem; elem++)
+ {
+ if (match_first_char (*elem, WC))
+ for (int i = 0; conv_envvars[i].name != NULL; i++)
+ if (strncmp (*elem, conv_envvars[i].name,
+ conv_envvars[i].namelen) == 0)
+ {
+ free (*elem);
+ memmove (elem, elem + 1,
+ (winnum - (elem - winenv)) * sizeof *elem);
+ --winnum;
+ --elem;
+ }
+ }
}
}