summaryrefslogtreecommitdiff
path: root/Source/Core/Common/CommonFuncs.cpp
diff options
context:
space:
mode:
authorshuffle2 <godisgovernment@gmail.com>2017-06-27 11:49:26 -0700
committerGitHub <noreply@github.com>2017-06-27 11:49:26 -0700
commitd19e1ed4bf608e2e38542a37ad25289d939fd4ff (patch)
tree3df382e43c2b43f9775323ef9c2b2cebbbc58c88 /Source/Core/Common/CommonFuncs.cpp
parentf1425a0c6041d3d070e46f6ef397451f0e5acae0 (diff)
parent5b7f99e57a09c8e026af5893e5c2b7aa2b1622d6 (diff)
Merge pull request #5705 from JosJuice/strerror-r-version
Try to make sure that we have the XSI version of strerror_r
Diffstat (limited to 'Source/Core/Common/CommonFuncs.cpp')
-rw-r--r--Source/Core/Common/CommonFuncs.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/Source/Core/Common/CommonFuncs.cpp b/Source/Core/Common/CommonFuncs.cpp
index 69ff018471..bfb2878dd3 100644
--- a/Source/Core/Common/CommonFuncs.cpp
+++ b/Source/Core/Common/CommonFuncs.cpp
@@ -2,8 +2,20 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
-#include <cstddef>
+// The code in GetErrorMessage can't handle some systems having the
+// GNU version of strerror_r and other systems having the XSI version,
+// so we undefine _GNU_SOURCE here in an attempt to always get the XSI version.
+// We include cstring before all other headers in case cstring is included
+// indirectly (without undefining _GNU_SOURCE) by some other header.
+#ifdef _GNU_SOURCE
+#undef _GNU_SOURCE
+#include <cstring>
+#define _GNU_SOURCE
+#else
#include <cstring>
+#endif
+
+#include <cstddef>
#include <errno.h>
#include "Common/CommonFuncs.h"
@@ -24,8 +36,11 @@ std::string GetLastErrorMsg()
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr);
#else
- // Thread safe (XSI-compliant)
- if (strerror_r(errno, err_str, buff_size))
+ // We assume that the XSI-compliant version of strerror_r (returns int) is used
+ // rather than the GNU version (returns char*). The returned value is stored to
+ // an int variable to get a compile-time check that the return type is not char*.
+ const int result = strerror_r(errno, err_str, buff_size);
+ if (result != 0)
return "";
#endif