diff options
| author | Sven Strickroth <email@cs-ware.de> | 2013-02-01 16:17:34 +0100 |
|---|---|---|
| committer | Sven Strickroth <email@cs-ware.de> | 2013-02-01 21:54:32 +0100 |
| commit | b0dc81f055d4eb523c92bc859d5641e72d343b00 (patch) | |
| tree | 0981338d512b39cb4e199769965a496abcde7ad6 /src/netops.c | |
| parent | aa3bf89df21c44f22fe70b4aac9109646fd06b48 (diff) | |
| download | libgit2-b0dc81f055d4eb523c92bc859d5641e72d343b00.tar.gz | |
Win32: Make sure error messages are consistently UTF-8 encoded
W/o this a libgit2 error message could have a mixed encoding:
e.g. a filename in UTF-8 combined with a native Windows error message
encoded with the local code page.
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Diffstat (limited to 'src/netops.c')
| -rw-r--r-- | src/netops.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/netops.c b/src/netops.c index 59e6bda1e..851ed4219 100644 --- a/src/netops.c +++ b/src/netops.c @@ -40,16 +40,20 @@ #ifdef GIT_WIN32 static void net_set_error(const char *str) { - int size, error = WSAGetLastError(); - LPSTR err_str = NULL; + int error = WSAGetLastError(); + LPWSTR err_str = NULL; - size = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - 0, error, 0, (LPSTR)&err_str, 0, 0); + int size = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&err_str, 0, 0); - GIT_UNUSED(size); + int utf8_size = size * 4 + 1; + char * err_str_utf8 = git__calloc(utf8_size, sizeof(char)); + GITERR_CHECK_ALLOC(err_str_utf8); + WideCharToMultiByte(CP_UTF8, 0, err_str, size, err_str_utf8, utf8_size, NULL, NULL); - giterr_set(GITERR_NET, "%s: %s", str, err_str); + giterr_set(GITERR_NET, "%s: %s", str, err_str_utf8); LocalFree(err_str); + git__free(err_str_utf8); } #else static void net_set_error(const char *str) |
