Skip to content

Commit 02e6edc

Browse files
kbleesgitster
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 888ab71 commit 02e6edc

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
@@ -2044,6 +2044,22 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
20442044
return -1;
20452045
}
20462046

2047+
static void setup_windows_environment()
2048+
{
2049+
/* on Windows it is TMP and TEMP */
2050+
if (!getenv("TMPDIR")) {
2051+
const char *tmp = getenv("TMP");
2052+
if (!tmp)
2053+
tmp = getenv("TEMP");
2054+
if (tmp)
2055+
setenv("TMPDIR", tmp, 1);
2056+
}
2057+
2058+
/* simulate TERM to enable auto-color (see color.c) */
2059+
if (!getenv("TERM"))
2060+
setenv("TERM", "cygwin", 1);
2061+
}
2062+
20472063
/*
20482064
* Disable MSVCRT command line wildcard expansion (__getmainargs called from
20492065
* mingw startup code, see init.c in mingw runtime).
@@ -2122,19 +2138,7 @@ void mingw_startup()
21222138
qsort(environ, i, sizeof(char*), compareenv);
21232139

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

21392143
/* initialize critical section for waitpid pinfo_t list */
21402144
InitializeCriticalSection(&pinfo_cs);

0 commit comments

Comments
 (0)