Skip to content

Commit 4a7ea16

Browse files
committed
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 <[email protected]>
1 parent 1e25c11 commit 4a7ea16

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compat/mingw.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,13 +1946,19 @@ struct passwd *getpwuid(int uid)
19461946
static unsigned initialized;
19471947
static char user_name[100];
19481948
static struct passwd *p;
1949+
wchar_t buf[100];
19491950
DWORD len;
19501951

19511952
if (initialized)
19521953
return p;
19531954

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) {
19561962
initialized = 1;
19571963
return NULL;
19581964
}

0 commit comments

Comments
 (0)