diff --git a/src/libimp/platform/posix/system.h b/src/libimp/platform/posix/system.h index 57396a9..1529643 100644 --- a/src/libimp/platform/posix/system.h +++ b/src/libimp/platform/posix/system.h @@ -4,10 +4,6 @@ */ #pragma once -#include -#include -#include - #include #include @@ -40,7 +36,13 @@ void error_code(result_code code) noexcept { * https://man7.org/linux/man-pages/man3/strerror_l.3.html */ std::string error_msg(result_code code) noexcept { - return {}; + LIBIMP_LOG_(); + char msg_buf[256] {}; + if (::strerror_r((int)code.value(), msg_buf, sizeof(msg_buf)) != 0) { + log.error("strerror_r fails. return = {}", error_code()); + return {}; + } + return msg_buf; } } // namespace sys diff --git a/src/libimp/platform/win/system.h b/src/libimp/platform/win/system.h index be23f92..5820e03 100644 --- a/src/libimp/platform/win/system.h +++ b/src/libimp/platform/win/system.h @@ -44,7 +44,7 @@ void error_code(result_code code) noexcept { std::string error_msg(result_code code) noexcept { LIBIMP_LOG_(); try { - DWORD err = code ? ERROR_SUCCESS : (DWORD)code.value(); + DWORD err = (DWORD)code.value(); LPTSTR lpErrText = NULL; if (::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | diff --git a/test/test_imp_system.cpp b/test/test_imp_system.cpp index e6e9f93..c64592f 100644 --- a/test/test_imp_system.cpp +++ b/test/test_imp_system.cpp @@ -52,5 +52,6 @@ TEST(system, error_msg) { EXPECT_EQ(imp::sys::error_msg({false, ERROR_INVALID_HANDLE}), s_txt); } #else + imp::sys::error_msg({false, 1234}, "Unknown error nnn"); #endif } \ No newline at end of file