From 123674474bb264f7836acab65af7437696d26663 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 2 Apr 2015 19:37:08 +0200 Subject: [PATCH] mingw: factor out Windows specific environment setup Signed-off-by: Karsten Blees --- compat/mingw.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 10ade6c6f6..88118e44c5 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -2226,6 +2226,22 @@ int handle_long_path(wchar_t *path, int len, int max_path, int expand) } } +static void setup_windows_environment() +{ + /* 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", "cygwin", 1); +} + /* * Disable MSVCRT command line wildcard expansion (__getmainargs called from * mingw startup code, see init.c in mingw runtime). @@ -2322,19 +2338,7 @@ void mingw_startup() 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); - } - - /* simulate TERM to enable auto-color (see color.c) */ - if (!getenv("TERM")) - setenv("TERM", "cygwin", 1); + setup_windows_environment(); /* * Avoid a segmentation fault when cURL tries to set the CHARSET