mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
Added errno description to sdlog exception strings
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -27,12 +28,16 @@
|
||||
#endif
|
||||
|
||||
#elif __linux__
|
||||
|
||||
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <chrono>
|
||||
|
||||
#else
|
||||
|
||||
#include <thread>
|
||||
|
||||
#endif
|
||||
|
||||
namespace spdlog
|
||||
@@ -246,6 +251,30 @@ inline std::string filename_to_str(const filename_t& filename)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Return errno string (thread safe)
|
||||
inline std::string errno_str(int err_num)
|
||||
{
|
||||
char buf[256];
|
||||
constexpr auto buf_size = sizeof(buf);
|
||||
|
||||
#ifdef _WIN32
|
||||
if(strerror_s(buf, buf_size, err_num) == 0)
|
||||
return std::string(buf);
|
||||
else
|
||||
return "Unkown error";
|
||||
|
||||
#elif (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE // posix version
|
||||
if (strerror_r(err_num, buf, buf_size) == 0)
|
||||
return std::string(buf);
|
||||
else
|
||||
return "Unkown error";
|
||||
|
||||
#else // gnu version (might not use the given buf, so its retval pointer must be used)
|
||||
return std::string(strerror_r(err_num, buf, buf_size));
|
||||
#endif
|
||||
}
|
||||
|
||||
} //os
|
||||
} //details
|
||||
} //spdlog
|
||||
|
Reference in New Issue
Block a user