mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
add: [system] error_msg for linux
This commit is contained in:
parent
bd198cb6e2
commit
cbda80e4b8
@ -4,10 +4,6 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 |
|
||||
|
||||
@ -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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user