aboutsummaryrefslogtreecommitdiff
path: root/src/util/syserror.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/syserror.cpp')
-rw-r--r--src/util/syserror.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util/syserror.cpp b/src/util/syserror.cpp
index 5270f55366..bac498a23d 100644
--- a/src/util/syserror.cpp
+++ b/src/util/syserror.cpp
@@ -12,6 +12,12 @@
#include <cstring>
#include <string>
+#if defined(WIN32)
+#include <windows.h>
+#include <locale>
+#include <codecvt>
+#endif
+
std::string SysErrorString(int err)
{
char buf[1024];
@@ -33,3 +39,21 @@ std::string SysErrorString(int err)
return strprintf("Unknown error (%d)", err);
}
}
+
+#if defined(WIN32)
+std::string Win32ErrorString(int err)
+{
+ wchar_t buf[256];
+ buf[0] = 0;
+ if(FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ nullptr, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ buf, ARRAYSIZE(buf), nullptr))
+ {
+ return strprintf("%s (%d)", std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().to_bytes(buf), err);
+ }
+ else
+ {
+ return strprintf("Unknown error (%d)", err);
+ }
+}
+#endif