diff options
author | gabime <gmelman1@gmail.com> | 2018-06-01 16:58:07 +0300 |
---|---|---|
committer | gabime <gmelman1@gmail.com> | 2018-06-01 16:58:07 +0300 |
commit | faea32c9f9b7c4d2e73c90780e4e0f81cf996d2a (patch) | |
tree | 86097ba790119035b42295eda4b834f646ed448d | |
parent | d78ddcee24397d760d213272aa41456a4d0992c5 (diff) |
simplfiy a little the use of fmt:safe_strerror
-rw-r--r-- | include/spdlog/common.h | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/include/spdlog/common.h b/include/spdlog/common.h index e6d9a557..1d8d954c 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -153,15 +153,18 @@ public: spdlog_ex(const std::string &msg, int last_errno) { + std::string errno_string; char buf[256], *buf_ptr = buf; - SPDLOG_CONSTEXPR auto buf_size = sizeof(buf); - if (fmt::safe_strerror(last_errno, buf_ptr, buf_size) != 0) + + if (fmt::safe_strerror(last_errno, buf_ptr, sizeof(buf)) == 0) + { + errno_string = buf_ptr; + } + else { - buf_ptr = buf; - char unknown[] = "Unknown error"; - std::copy(unknown, unknown + sizeof(unknown), buf_ptr); + errno_string = "Unknown error"; } - _msg = msg + ": " + std::string(buf_ptr); + _msg = msg + ": " + errno_string; } const char *what() const SPDLOG_NOEXCEPT override @@ -182,6 +185,13 @@ using filename_t = std::wstring; using filename_t = std::string; #endif -#define SPDLOG_CATCH_AND_HANDLE catch (const std::exception &ex) {_err_handler(ex.what());}\ - catch (...) {_err_handler("Unknown exeption in logger");} +#define SPDLOG_CATCH_AND_HANDLE \ + catch (const std::exception &ex) \ + { \ + _err_handler(ex.what()); \ + } \ + catch (...) \ + { \ + _err_handler("Unknown exeption in logger"); \ + } } // namespace spdlog |