summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-06-27 09:37:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-27 19:56:13 (GMT)
commit39a98e9b68b84e40e759a0805758ec4726c9299e (patch)
tree41338509df935657834aac972d69bb78ad0d1541
parent8dca754b1e874719a732bc9ab7b0e14b21b1bc10 (diff)
downloadgit-39a98e9b68b84e40e759a0805758ec4726c9299e.zip
git-39a98e9b68b84e40e759a0805758ec4726c9299e.tar.gz
git-39a98e9b68b84e40e759a0805758ec4726c9299e.tar.bz2
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>
-rw-r--r--compat/mingw.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 9b6d240..8526876 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1946,13 +1946,19 @@ struct passwd *getpwuid(int uid)
static unsigned initialized;
static char user_name[100];
static struct passwd *p;
+ wchar_t buf[100];
DWORD len;
if (initialized)
return p;
- len = sizeof(user_name);
- if (!GetUserName(user_name, &len)) {
+ len = sizeof(buf);
+ if (!GetUserNameW(buf, &len)) {
+ initialized = 1;
+ return NULL;
+ }
+
+ if (xwcstoutf(user_name, buf, sizeof(user_name)) < 0) {
initialized = 1;
return NULL;
}