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 <blees@dcon.de> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Jan 26, 2016 at 15:34 UTC 02e6edc082969c3f52ea954e71b391410632dfba
1 file changed +17 -13
compat/mingw.c
+17 -13
@@ -2044,6 +2044,22 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen)
2044 return -1;
2045 }
2046
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 +
2063 /*
2064 * Disable MSVCRT command line wildcard expansion (__getmainargs called from
2065 * mingw startup code, see init.c in mingw runtime).
@@ -2122,19 +2138,7 @@ void mingw_startup()
2138 qsort(environ, i, sizeof(char*), compareenv);
2139
2140 /* 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();
2142
2143 /* initialize critical section for waitpid pinfo_t list */
2144 InitializeCriticalSection(&pinfo_cs);