13 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
17 #elif defined(_WIN32) || defined(_WIN64)
25 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
27 #elif defined(_WIN32) || defined(_WIN64)
28 return GetLastError();
34 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
36 #elif defined(_WIN32) || defined(_WIN64)
37 return SetLastError(error);
48 const int capacity = 1024;
49 #if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
50 char buffer[capacity];
51 #if defined(__APPLE__) || defined(__CYGWIN__)
52 int result = strerror_r(error, buffer, capacity);
55 char* result = strerror_r(error, buffer, capacity);
56 if (result ==
nullptr)
58 return format(
"Cannot convert the given system error code to the system message - {}", error);
60 return std::string(buffer);
61 #elif defined(_WIN32) || defined(_WIN64)
62 WCHAR buffer[capacity];
63 DWORD size = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, capacity,
nullptr);
64 return Encoding::ToUTF8((size >= 2) ? std::wstring(buffer, (size - 2)) : std::wstring(L
"Unknown system error!"));
static std::string ToUTF8(std::wstring_view wstr)
Convert system wide-string to UTF-8 encoded string.
static void ClearLast() noexcept
Clear the last system error code.
static int GetLast() noexcept
Get the last system error code.
static std::string Description()
Convert the last system error code to the system error description.
static void SetLast(int error) noexcept
Set the last system error code.
Encoding utilities definition.
C++ Common project definitions.
std::string format(fmt::format_string< T... > pattern, T &&... args)
Format string.