mirror of
https://github.com/git/git.git
synced 2026-02-07 00:05:02 +00:00
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>
This commit is contained in:
committed by
Stepan Kasal
parent
7f7675e937
commit
80e6f0f8be
@@ -785,7 +785,7 @@ static int environ_size = 0;
|
||||
/* allocated size of environ array, in bytes */
|
||||
static int environ_alloc = 0;
|
||||
|
||||
static char *do_getenv(const char *name)
|
||||
char *mingw_getenv(const char *name)
|
||||
{
|
||||
char *value;
|
||||
int pos = bsearchenv(environ, name, environ_size - 1);
|
||||
@@ -795,22 +795,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");
|
||||
}
|
||||
else if (!result && !strcmp(name, "TERM")) {
|
||||
/* simulate TERM to enable auto-color (see color.c) */
|
||||
result = "winansi";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int mingw_putenv(const char *namevalue)
|
||||
{
|
||||
ALLOC_GROW(environ, (environ_size + 1) * sizeof(char*), environ_alloc);
|
||||
@@ -2088,6 +2072,21 @@ 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 (!getenv("TMPDIR")) {
|
||||
const char *tmp = getenv("TMP");
|
||||
if (!tmp)
|
||||
tmp = getenv("TEMP");
|
||||
if (tmp)
|
||||
setenv("TMPDIR", tmp, 1);
|
||||
}
|
||||
|
||||
/* simulate TERM to enable auto-color (see color.c) */
|
||||
if (!getenv("TERM"))
|
||||
setenv("TERM", "winansi", 1);
|
||||
|
||||
/* initialize critical section for waitpid pinfo_t list */
|
||||
InitializeCriticalSection(&pinfo_cs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user