diff options
author | Max Kellermann <max@duempel.org> | 2015-02-25 16:01:46 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-03-05 10:15:10 +0100 |
commit | 65ff72cdf8d3fc8664893b55ca47fca284f34d87 (patch) | |
tree | 766eca97378aa4567d7e55aba24c4a785f956f9d /src/net | |
parent | 1da09563310a666095e93d3b4fdc5556a8a7c534 (diff) | |
download | mpd-65ff72cdf8d3fc8664893b55ca47fca284f34d87.tar.gz mpd-65ff72cdf8d3fc8664893b55ca47fca284f34d87.tar.xz mpd-65ff72cdf8d3fc8664893b55ca47fca284f34d87.zip |
fs/Traits: enable _UNICODE on Windows
Use wchar_t for everything on Windows. Solves a lot of filesystem
charset problems.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/SocketError.cxx | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/net/SocketError.cxx b/src/net/SocketError.cxx index c4c9d7a2c..efa969b1f 100644 --- a/src/net/SocketError.cxx +++ b/src/net/SocketError.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "SocketError.hxx" #include "util/Domain.hxx" +#include "util/Macros.hxx" #include <string.h> @@ -29,13 +30,31 @@ const Domain socket_domain("socket"); SocketErrorMessage::SocketErrorMessage(socket_error_t code) { +#ifdef _UNICODE + wchar_t buffer[ARRAY_SIZE(msg)]; +#else + auto *buffer = msg; +#endif + DWORD nbytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, - NULL, code, 0, - (LPSTR)msg, sizeof(msg), NULL); - if (nbytes == 0) + nullptr, code, 0, + buffer, ARRAY_SIZE(msg), nullptr); + if (nbytes == 0) { strcpy(msg, "Unknown error"); + return; + } + +#ifdef _UNICODE + auto length = WideCharToMultiByte(CP_UTF8, 0, buffer, -1, + msg, ARRAY_SIZE(msg), + nullptr, nullptr); + if (length <= 0) { + strcpy(msg, "WideCharToMultiByte() error"); + return; + } +#endif } #else |