From 97cc0ef62b3ad2b8eb93616e3ecada8fba4e6cc7 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 12 Mar 2022 23:35:26 +0900 Subject: [PATCH] fix #166: reorder local/gmtime wrapper for MSVC --- toml/datetime.hpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/toml/datetime.hpp b/toml/datetime.hpp index d8127c1..36db1e1 100644 --- a/toml/datetime.hpp +++ b/toml/datetime.hpp @@ -21,22 +21,7 @@ namespace toml namespace detail { // TODO: find more sophisticated way to handle this -#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE) -inline std::tm localtime_s(const std::time_t* src) -{ - std::tm dst; - const auto result = ::localtime_r(src, &dst); - if (!result) { throw std::runtime_error("localtime_r failed."); } - return dst; -} -inline std::tm gmtime_s(const std::time_t* src) -{ - std::tm dst; - const auto result = ::gmtime_r(src, &dst); - if (!result) { throw std::runtime_error("gmtime_r failed."); } - return dst; -} -#elif defined(_MSC_VER) +#if defined(_MSC_VER) inline std::tm localtime_s(const std::time_t* src) { std::tm dst; @@ -51,6 +36,21 @@ inline std::tm gmtime_s(const std::time_t* src) if (result) { throw std::runtime_error("gmtime_s failed."); } return dst; } +#elif (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || defined(_POSIX_SOURCE) +inline std::tm localtime_s(const std::time_t* src) +{ + std::tm dst; + const auto result = ::localtime_r(src, &dst); + if (!result) { throw std::runtime_error("localtime_r failed."); } + return dst; +} +inline std::tm gmtime_s(const std::time_t* src) +{ + std::tm dst; + const auto result = ::gmtime_r(src, &dst); + if (!result) { throw std::runtime_error("gmtime_r failed."); } + return dst; +} #else // fallback. not threadsafe inline std::tm localtime_s(const std::time_t* src) {