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>
This commit is contained in:
parent
8dca754b1e
commit
39a98e9b68
@ -1946,13 +1946,19 @@ struct passwd *getpwuid(int uid)
|
|||||||
static unsigned initialized;
|
static unsigned initialized;
|
||||||
static char user_name[100];
|
static char user_name[100];
|
||||||
static struct passwd *p;
|
static struct passwd *p;
|
||||||
|
wchar_t buf[100];
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
|
||||||
if (initialized)
|
if (initialized)
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
len = sizeof(user_name);
|
len = sizeof(buf);
|
||||||
if (!GetUserName(user_name, &len)) {
|
if (!GetUserNameW(buf, &len)) {
|
||||||
|
initialized = 1;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
|
||||||
initialized = 1;
|
initialized = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user