Skip to content

Commit cf1cfe8

Browse files
kbleesdscho
authored andcommitted
mingw: factor out Windows specific environment setup
We will add more environment-related code to that new function in the next patch. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 1d21978 commit cf1cfe8

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

compat/mingw.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,22 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
20472047
return -1;
20482048
}
20492049

2050+
static void setup_windows_environment()
2051+
{
2052+
/* on Windows it is TMP and TEMP */
2053+
if (!getenv("TMPDIR")) {
2054+
const char *tmp = getenv("TMP");
2055+
if (!tmp)
2056+
tmp = getenv("TEMP");
2057+
if (tmp)
2058+
setenv("TMPDIR", tmp, 1);
2059+
}
2060+
2061+
/* simulate TERM to enable auto-color (see color.c) */
2062+
if (!getenv("TERM"))
2063+
setenv("TERM", "cygwin", 1);
2064+
}
2065+
20502066
/*
20512067
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
20522068
* mingw startup code, see init.c in mingw runtime).
@@ -2125,19 +2141,7 @@ void mingw_startup()
21252141
qsort(environ, i, sizeof(char*), compareenv);
21262142

21272143
/* fix Windows specific environment settings */
2128-
2129-
/* on Windows it is TMP and TEMP */
2130-
if (!mingw_getenv("TMPDIR")) {
2131-
const char *tmp = mingw_getenv("TMP");
2132-
if (!tmp)
2133-
tmp = mingw_getenv("TEMP");
2134-
if (tmp)
2135-
setenv("TMPDIR", tmp, 1);
2136-
}
2137-
2138-
/* simulate TERM to enable auto-color (see color.c) */
2139-
if (!getenv("TERM"))
2140-
setenv("TERM", "cygwin", 1);
2144+
setup_windows_environment();
21412145

21422146
/* initialize critical section for waitpid pinfo_t list */
21432147
InitializeCriticalSection(&pinfo_cs);

0 commit comments

Comments
 (0)