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; }