mingw: get pw_name in UTF-8 format

Previously, we would have obtained the user name encoded in whatever the current code page is. Note: the "user name" here does not denote the full name but instead the short logon name. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 27, 2019 at 02:37 UTC 39a98e9b68b84e40e759a0805758ec4726c9299e
1 file changed +8 -2
compat/mingw.c
+8 -2
@@ -1946,13 +1946,19 @@ struct passwd *getpwuid(int uid)
1946 static unsigned initialized;
1947 static char user_name[100];
1948 static struct passwd *p;
1949 + wchar_t buf[100];
1950 DWORD len;
1951
1952 if (initialized)
1953 return p;
1954
1954 - len = sizeof(user_name);
1955 - if (!GetUserName(user_name, &len)) {
1955 + len = sizeof(buf);
1956 + if (!GetUserNameW(buf, &len)) {
1957 + initialized = 1;
1958 + return NULL;
1959 + }
1960 +
1961 + if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
1962 initialized = 1;
1963 return NULL;
1964 }