From 4583e6bebd5a335f8ea8f66d410d5e921946aeec Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 23 Apr 2015 16:55:53 +0100 Subject: [PATCH] squash! Windows: use %PROGRAMDATA%\Git\config as Windows-wide configuration On XP, there is no %PROGRAMDATA%, therefore we need to use "%ALLUSERSPROFILE%\Application Data\Git\config" in those setups. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 043b847ec1..507c038ba6 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1,6 +1,7 @@ #include "../git-compat-util.h" #include "win32.h" #include +#include #include #include "../strbuf.h" #include "../run-command.h" @@ -2382,8 +2383,16 @@ void mingw_startup() const char *windows_wide_config(void) { static struct strbuf windows_wide = STRBUF_INIT; - if (!windows_wide.len) - strbuf_addf(&windows_wide, - "%s\\Git\\config", getenv("PROGRAMDATA")); - return windows_wide.buf; + if (!windows_wide.len) { + char wbuffer[MAX_PATH]; + if (SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, + SHGFP_TYPE_CURRENT, wbuffer) != S_OK) + strbuf_addch(&windows_wide, '\0'); + else { + char buffer[MAX_PATH]; + xwcstoutf(buffer, wbuffer, sizeof(buffer)); + strbuf_addf(&windows_wide, "%s\\Git\\config", buffer); + } + } + return *windows_wide.buf ? windows_wide.buf : NULL; }