Skip to content

Commit

Permalink
mingw.c: move definition of mingw_getenv down
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
j6t authored and gitster committed Jun 6, 2011
1 parent 8c92516 commit 06bc4b7
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions compat/mingw.c
Expand Up @@ -178,7 +178,7 @@ static int ask_yes_no_if_possible(const char *format, ...)
vsnprintf(question, sizeof(question), format, args);
va_end(args);

if ((retry_hook[0] = getenv("GIT_ASK_YESNO"))) {
if ((retry_hook[0] = mingw_getenv("GIT_ASK_YESNO"))) {
retry_hook[1] = question;
return !run_command_v_opt(retry_hook, 0);
}
Expand Down Expand Up @@ -599,19 +599,6 @@ char *mingw_getcwd(char *pointer, int len)
return ret;
}

#undef getenv
char *mingw_getenv(const char *name)
{
char *result = getenv(name);
if (!result && !strcmp(name, "TMPDIR")) {
/* on Windows it is TMP and TEMP */
result = getenv("TMP");
if (!result)
result = getenv("TEMP");
}
return result;
}

/*
* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx
* (Parsing C++ Command-Line Arguments)
Expand Down Expand Up @@ -711,7 +698,7 @@ static const char *parse_interpreter(const char *cmd)
*/
static char **get_path_split(void)
{
char *p, **path, *envpath = getenv("PATH");
char *p, **path, *envpath = mingw_getenv("PATH");
int i, n = 0;

if (!envpath || !*envpath)
Expand Down Expand Up @@ -1128,6 +1115,19 @@ char **make_augmented_environ(const char *const *vars)
return env;
}

#undef getenv
char *mingw_getenv(const char *name)
{
char *result = getenv(name);
if (!result && !strcmp(name, "TMPDIR")) {
/* on Windows it is TMP and TEMP */
result = getenv("TMP");
if (!result)
result = getenv("TEMP");
}
return result;
}

/*
* Note, this isn't a complete replacement for getaddrinfo. It assumes
* that service contains a numerical port, or that it is null. It
Expand Down

0 comments on commit 06bc4b7

Please sign in to comment.