Skip to content

Commit 7cf417e

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 4bb45e9 commit 7cf417e

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
@@ -2109,13 +2109,19 @@ struct passwd *getpwuid(int uid)
21092109
static unsigned initialized;
21102110
static char user_name[100];
21112111
static struct passwd *p;
2112+
wchar_t buf[100];
21122113
DWORD len;
21132114

21142115
if (initialized)
21152116
return p;
21162117

2117-
len = sizeof(user_name);
2118-
if (!GetUserName(user_name, &len)) {
2118+
len = sizeof(buf);
2119+
if (!GetUserNameW(buf, &len)) {
2120+
initialized = 1;
2121+
return NULL;
2122+
}
2123+
2124+
if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
21192125
initialized = 1;
21202126
return NULL;
21212127
}

0 commit comments

Comments
 (0)