mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-04 00:38:47 +00:00
Fix strerror_r thingy
This commit is contained in:
+9
-5
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
@@ -22,12 +24,14 @@ std::string GetLastErrorMsg() {
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr);
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr);
|
||||||
#elif defined(__GNUC__)
|
|
||||||
const char* err = strerror_r(errno, err_str, buff_size);
|
|
||||||
return std::string(err, strlen(err));
|
|
||||||
#else
|
#else
|
||||||
// Thread safe (XSI-compliant)
|
auto ret = strerror_r(errno, err_str, buff_size);
|
||||||
strerror_r(errno, err_str, buff_size);
|
if constexpr (std::is_same_v<decltype(ret), const char*>) {
|
||||||
|
// GNU specific
|
||||||
|
// This is a workaround for XSI-compliant variant; this should always be safe.
|
||||||
|
const char* str = reinterpret_cast<const char*>(ret);
|
||||||
|
return std::string(str, strlen(str));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return std::string(err_str, strnlen(err_str, buff_size));
|
return std::string(err_str, strnlen(err_str, buff_size));
|
||||||
|
|||||||
Reference in New Issue
Block a user