From 3c965bf3715bce76e69ad8fecee99dca4678d676 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 23 Jun 2008 10:53:04 +0200 Subject: [PATCH] Handle getenv("TMPDIR") in a getenv() wrapper. This removes an #ifdef MINGW in path.c. Signed-off-by: Johannes Sixt --- compat/mingw.c | 13 +++++++++++++ compat/mingw.h | 3 +++ path.c | 7 ------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 488ff404ce..116b4ca970 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -366,6 +366,19 @@ 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) diff --git a/compat/mingw.h b/compat/mingw.h index 6965e3f2df..6bc049ad99 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -145,6 +145,9 @@ int mingw_open (const char *filename, int oflags, ...); char *mingw_getcwd(char *pointer, int len); #define getcwd mingw_getcwd +char *mingw_getenv(const char *name); +#define getenv mingw_getenv + struct hostent *mingw_gethostbyname(const char *host); #define gethostbyname mingw_gethostbyname diff --git a/path.c b/path.c index 5da41c709d..7a35a26a16 100644 --- a/path.c +++ b/path.c @@ -75,13 +75,6 @@ int git_mkstemp(char *path, size_t len, const char *template) size_t n; tmp = getenv("TMPDIR"); -#ifdef __MINGW32__ - /* on Windows it is TMP and TEMP */ - if (!tmp) - tmp = getenv("TMP"); - if (!tmp) - tmp = getenv("TEMP"); -#endif if (!tmp) tmp = "/tmp"; n = snprintf(path, len, "%s/%s", tmp, template);