summaryrefslogtreecommitdiff
path: root/src/SocketCore.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-01-28 22:25:46 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-01-28 22:25:46 +0900
commit25243da03917b7e36a96a3d28bf99cb578501602 (patch)
tree32e6f3def966075c1287a4fbc27ed3a6fd060e9f /src/SocketCore.cc
parentad6d799b98582250aad50db96519fc7242f6e88a (diff)
mingw: Add formatLastError as wrapper function for FormatMessage
Diffstat (limited to 'src/SocketCore.cc')
-rw-r--r--src/SocketCore.cc11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/SocketCore.cc b/src/SocketCore.cc
index 8358527e..50e974f5 100644
--- a/src/SocketCore.cc
+++ b/src/SocketCore.cc
@@ -105,14 +105,13 @@ std::string errorMsg(int errNum)
#ifndef __MINGW32__
return util::safeStrerror(errNum);
#else
- static char buf[256];
- if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- nullptr, errNum,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPTSTR)&buf,
- sizeof(buf), nullptr) == 0) {
+ auto msg = util::formatLastError(errNum);
+ if (msg.empty()) {
+ char buf[256];
snprintf(buf, sizeof(buf), EX_SOCKET_UNKNOWN_ERROR, errNum, errNum);
+ return buf;
}
- return buf;
+ return msg;
#endif // __MINGW32__
}
} // namespace