@@ -178,7 +178,7 @@ static int ask_yes_no_if_possible(const char *format, ...)
178178 vsnprintf (question , sizeof (question ), format , args );
179179 va_end (args );
180180
181- if ((retry_hook [0 ] = getenv ("GIT_ASK_YESNO" ))) {
181+ if ((retry_hook [0 ] = mingw_getenv ("GIT_ASK_YESNO" ))) {
182182 retry_hook [1 ] = question ;
183183 return !run_command_v_opt (retry_hook , 0 );
184184 }
@@ -599,19 +599,6 @@ char *mingw_getcwd(char *pointer, int len)
599599 return ret ;
600600}
601601
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-
615602/*
616603 * See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
617604 * (Parsing C++ Command-Line Arguments)
@@ -711,7 +698,7 @@ static const char *parse_interpreter(const char *cmd)
711698 */
712699static char * * get_path_split (void )
713700{
714- char * p , * * path , * envpath = getenv ("PATH" );
701+ char * p , * * path , * envpath = mingw_getenv ("PATH" );
715702 int i , n = 0 ;
716703
717704 if (!envpath || !* envpath )
@@ -1128,6 +1115,36 @@ char **make_augmented_environ(const char *const *vars)
11281115 return env ;
11291116}
11301117
1118+ #undef getenv
1119+
1120+ /*
1121+ * The system's getenv looks up the name in a case-insensitive manner.
1122+ * This version tries a case-sensitive lookup and falls back to
1123+ * case-insensitive if nothing was found. This is necessary because,
1124+ * as a prominent example, CMD sets 'Path', but not 'PATH'.
1125+ * Warning: not thread-safe.
1126+ */
1127+ static char * getenv_cs (const char * name )
1128+ {
1129+ size_t len = strlen (name );
1130+ int i = lookup_env (environ , name , len );
1131+ if (i >= 0 )
1132+ return environ [i ] + len + 1 ; /* skip past name and '=' */
1133+ return getenv (name );
1134+ }
1135+
1136+ char * mingw_getenv (const char * name )
1137+ {
1138+ char * result = getenv_cs (name );
1139+ if (!result && !strcmp (name , "TMPDIR" )) {
1140+ /* on Windows it is TMP and TEMP */
1141+ result = getenv_cs ("TMP" );
1142+ if (!result )
1143+ result = getenv_cs ("TEMP" );
1144+ }
1145+ return result ;
1146+ }
1147+
11311148/*
11321149 * Note, this isn't a complete replacement for getaddrinfo. It assumes
11331150 * that service contains a numerical port, or that it is null. It
0 commit comments