mingw.c: move definition of mingw_getenv down

We want to use static lookup_env() in a subsequent change. At first sight, this change looks innocent. But it is not due to the #undef getenv. There is one caller of getenv between the old location and the new location whose behavior could change. But as can be seen from the defintion of mingw_getenv, the behavior for this caller does not change substantially. To ensure consistent behavior in the future, change all getenv callers in mingw.c to use mingw_getenv. With this patch, this is not a big deal, yet, but with the subsequent change, where we teach getenv to do a case-sensitive lookup, the behavior of all call sites is changed. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jun 6, 2011 at 09:06 UTC 06bc4b796ad69ba93f0a8c451368602e0553c2d3
1 file changed +15 -15
compat/mingw.c
+15 -15
@@ -178,7 +178,7 @@ static int ask_yes_no_if_possible(const char *format, ...)
178 vsnprintf(question, sizeof(question), format, args);
179 va_end(args);
180
181 - if ((retry_hook[0] = getenv("GIT_ASK_YESNO"))) {
181 + if ((retry_hook[0] = mingw_getenv("GIT_ASK_YESNO"))) {
182 retry_hook[1] = question;
183 return !run_command_v_opt(retry_hook, 0);
184 }
@@ -599,19 +599,6 @@ char *mingw_getcwd(char *pointer, int len)
599 return ret;
600 }
601
602 -#undef getenv
603 -char *mingw_getenv(const char *name)
604 -{
605 - char *result = getenv(name);
606 - if (!result && !strcmp(name, "TMPDIR")) {
607 - /* on Windows it is TMP and TEMP */
608 - result = getenv("TMP");
609 - if (!result)
610 - result = getenv("TEMP");
611 - }
612 - return result;
613 -}
614 -
602 /*
603 * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
604 * (Parsing C++ Command-Line Arguments)
@@ -711,7 +698,7 @@ static const char *parse_interpreter(const char *cmd)
698 */
699 static char **get_path_split(void)
700 {
714 - char *p, **path, *envpath = getenv("PATH");
701 + char *p, **path, *envpath = mingw_getenv("PATH");
702 int i, n = 0;
703
704 if (!envpath || !*envpath)
@@ -1128,6 +1115,19 @@ char **make_augmented_environ(const char *const *vars)
1115 return env;
1116 }
1117
1118 +#undef getenv
1119 +char *mingw_getenv(const char *name)
1120 +{
1121 + char *result = getenv(name);
1122 + if (!result && !strcmp(name, "TMPDIR")) {
1123 + /* on Windows it is TMP and TEMP */
1124 + result = getenv("TMP");
1125 + if (!result)
1126 + result = getenv("TEMP");
1127 + }
1128 + return result;
1129 +}
1130 +
1131 /*
1132 * Note, this isn't a complete replacement for getaddrinfo. It assumes
1133 * that service contains a numerical port, or that it is null. It