summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorAlex Tanskanen <aleta@cendio.com>2020-03-04 10:27:02 +0100
committerAlex Tanskanen <aleta@cendio.com>2020-03-12 15:46:04 +0100
commitfb8131f7a2e93b67887e0b0a3b308a6905d95746 (patch)
tree4cf18e7e35e2bc3ee916709955017f7314c35c89 /common
parent2b45fb39504b72147984a18e880e0cd6acce98ce (diff)
downloadtigervnc-fb8131f7a2e93b67887e0b0a3b308a6905d95746.tar.gz
tigervnc-fb8131f7a2e93b67887e0b0a3b308a6905d95746.zip
Make system error messeges in Windows 10 use UTF-8
The previous error messages did not support Unicode characters. This commit will use UTF-8 encoding to be able to display error messages in every language.
Diffstat (limited to 'common')
-rw-r--r--common/rdr/Exception.cxx35
1 files changed, 9 insertions, 26 deletions
diff --git a/common/rdr/Exception.cxx b/common/rdr/Exception.cxx
index 964bc333..e0592b29 100644
--- a/common/rdr/Exception.cxx
+++ b/common/rdr/Exception.cxx
@@ -54,33 +54,16 @@ SystemException::SystemException(const char* s, int err_)
{
strncat(str_, ": ", len-1-strlen(str_));
#ifdef _WIN32
- // Windows error messages are crap, so use unix ones for common errors.
- const char* msg = 0;
- switch (err) {
- case WSAECONNREFUSED: msg = "Connection refused"; break;
- case WSAETIMEDOUT: msg = "Connection timed out"; break;
- case WSAECONNRESET: msg = "Connection reset by peer"; break;
- case WSAECONNABORTED: msg = "Connection aborted"; break;
- }
- if (msg) {
- strncat(str_, msg, len-1-strlen(str_));
- } else {
-#ifdef UNICODE
- WCHAR* tmsg = new WCHAR[len-strlen(str_)];
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- 0, err, 0, tmsg, len-1-strlen(str_), 0);
- WideCharToMultiByte(CP_ACP, 0, tmsg, wcslen(tmsg)+1,
- str_+strlen(str_), len-strlen(str_), 0, 0);
- delete [] tmsg;
-#else
- char* currStr = str_+strlen(str_);
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- 0, err, 0, currStr, len-1-strlen(str_), 0);
-#endif
- int l = strlen(str_);
- if ((l >= 2) && (str_[l-2] == '\r') && (str_[l-1] == '\n'))
+ wchar_t *currStr = new wchar_t[len-strlen(str_)];
+ FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ 0, err, 0, currStr, len-1-strlen(str_), 0);
+ WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_),
+ len-1-strlen(str_), 0, 0);
+ delete [] currStr;
+
+ int l = strlen(str_);
+ if ((l >= 2) && (str_[l-2] == '\r') && (str_[l-1] == '\n'))
str_[l-2] = 0;
- }
#else
strncat(str_, strerror(err), len-1-strlen(str_));