mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-13 17:22:06 +08:00
Move errno code into common
errno code is no longer OS specific. Moving to common.
This commit is contained in:
parent
aa9012fa07
commit
7bc598c9b5
@ -143,11 +143,6 @@ enum class pattern_time_type
|
||||
//
|
||||
// Log exception
|
||||
//
|
||||
namespace details {
|
||||
namespace os {
|
||||
std::string errno_str(int err_num);
|
||||
}
|
||||
} // namespace details
|
||||
class spdlog_ex : public std::exception
|
||||
{
|
||||
public:
|
||||
@ -158,7 +153,15 @@ public:
|
||||
|
||||
spdlog_ex(const std::string &msg, int last_errno)
|
||||
{
|
||||
_msg = msg + ": " + details::os::errno_str(last_errno);
|
||||
char buf[256], *buf_ptr = buf;
|
||||
SPDLOG_CONSTEXPR auto buf_size = sizeof(buf);
|
||||
if (fmt::safe_strerror(last_errno, buf_ptr, buf_size) != 0)
|
||||
{
|
||||
buf_ptr = buf;
|
||||
char unknown[] = "Unknown error";
|
||||
std::copy(unknown, unknown + sizeof(unknown), buf_ptr);
|
||||
}
|
||||
_msg = msg + ": " + std::string(buf_ptr);
|
||||
}
|
||||
|
||||
const char *what() const SPDLOG_NOEXCEPT override
|
||||
|
@ -383,18 +383,6 @@ 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], *buf_ptr = buf;
|
||||
SPDLOG_CONSTEXPR auto buf_size = sizeof(buf);
|
||||
if (fmt::safe_strerror(err_num, buf_ptr, buf_size) == 0)
|
||||
{
|
||||
return std::string(buf_ptr);
|
||||
}
|
||||
return "Unknown error";
|
||||
}
|
||||
|
||||
inline int pid()
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user