summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarsten Blees <blees@dcon.de>2014-07-17 17:38:05 +0200
committerJunio C Hamano <gitster@pobox.com>2014-07-21 09:32:50 -0700
commit6dc715439b8e9ec85d6412750665431dd6a5afc6 (patch)
treeb8584c68e2419454c2ea4944da3b38b177255389
parent343ff06da7d83f40892b10a3b653c7d0e6cb526c (diff)
downloadgit-6dc715439b8e9ec85d6412750665431dd6a5afc6.tar.gz
Win32: patch Windows environment on startup
Fix Windows specific environment settings on startup rather than checking for special values on every getenv call. As a side effect, this makes the patched environment (i.e. with properly initialized TMPDIR and TERM) available to child processes. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Stepan Kasal <kasal@ucw.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--compat/mingw.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 968e8d3c3e..74c6180a20 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1251,7 +1251,7 @@ static int do_putenv(char **env, const char *name, int size, int free_old)
return size;
}
-static char *do_getenv(const char *name)
+char *mingw_getenv(const char *name)
{
char *value;
int pos = bsearchenv(environ, name, environ_size - 1);
@@ -1261,18 +1261,6 @@ static char *do_getenv(const char *name)
return value ? &value[1] : NULL;
}
-char *mingw_getenv(const char *name)
-{
- char *result = do_getenv(name);
- if (!result && !strcmp(name, "TMPDIR")) {
- /* on Windows it is TMP and TEMP */
- result = do_getenv("TMP");
- if (!result)
- result = do_getenv("TEMP");
- }
- return result;
-}
-
int mingw_putenv(const char *namevalue)
{
ALLOC_GROW(environ, (environ_size + 1) * sizeof(char*), environ_alloc);
@@ -2114,6 +2102,17 @@ void mingw_startup()
/* sort environment for O(log n) getenv / putenv */
qsort(environ, i, sizeof(char*), compareenv);
+ /* fix Windows specific environment settings */
+
+ /* on Windows it is TMP and TEMP */
+ if (!mingw_getenv("TMPDIR")) {
+ const char *tmp = mingw_getenv("TMP");
+ if (!tmp)
+ tmp = mingw_getenv("TEMP");
+ if (tmp)
+ setenv("TMPDIR", tmp, 1);
+ }
+
/* initialize critical section for waitpid pinfo_t list */
InitializeCriticalSection(&pinfo_cs);