mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 10:28:09 +08:00
feat: add thread-safe detail::gmtime_s
This commit is contained in:
@@ -28,6 +28,13 @@ inline std::tm localtime_s(const std::time_t* src)
|
|||||||
if (!result) { throw std::runtime_error("localtime_r failed."); }
|
if (!result) { throw std::runtime_error("localtime_r failed."); }
|
||||||
return dst;
|
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 _MSC_VER
|
#elif _MSC_VER
|
||||||
inline std::tm localtime_s(const std::time_t* src)
|
inline std::tm localtime_s(const std::time_t* src)
|
||||||
{
|
{
|
||||||
@@ -36,13 +43,26 @@ inline std::tm localtime_s(const std::time_t* src)
|
|||||||
if (result) { throw std::runtime_error("localtime_s failed."); }
|
if (result) { throw std::runtime_error("localtime_s failed."); }
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
#else
|
inline std::tm gmtime_s(const std::time_t* src)
|
||||||
|
{
|
||||||
|
std::tm dst;
|
||||||
|
const auto result = ::gmtime_s(&dst, src);
|
||||||
|
if (result) { throw std::runtime_error("gmtime_s failed."); }
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
#else // fallback. not threadsafe
|
||||||
inline std::tm localtime_s(const std::time_t* src)
|
inline std::tm localtime_s(const std::time_t* src)
|
||||||
{
|
{
|
||||||
const auto result = std::localtime(src);
|
const auto result = std::localtime(src);
|
||||||
if (!result) { throw std::runtime_error("localtime failed."); }
|
if (!result) { throw std::runtime_error("localtime failed."); }
|
||||||
return *result;
|
return *result;
|
||||||
}
|
}
|
||||||
|
inline std::tm gmtime_s(const std::time_t* src)
|
||||||
|
{
|
||||||
|
const auto result = std::gmtime(src);
|
||||||
|
if (!result) { throw std::runtime_error("gmtime failed."); }
|
||||||
|
return *result;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user