diff options
author | lloyd <[email protected]> | 2009-12-24 21:40:12 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-12-24 21:40:12 +0000 |
commit | 986ca995a1a8705cf4231345b44fc4617322e971 (patch) | |
tree | 19fe903545e331d156da8ecc839f64fddaf040e5 | |
parent | a48ae8f6c1aa605acbed76e9e2f1d6c2dcdd3d1e (diff) |
Wrap up whatever we're using for gmtime in an anon-namespace function do_gmtime
-rw-r--r-- | src/utils/time.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/utils/time.cpp b/src/utils/time.cpp index e1e7d1f20..2de992c9d 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -47,6 +47,24 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) return res; } +std::tm do_gmtime(time_t time_val) + { + std::tm tm; + +#if defined(BOTAN_TARGET_OS_HAS_GMTIME_S) + gmtime_s(&tm, &time_val); // Windows +#elif defined(BOTAN_TARGET_OS_HAS_GMTIME_R) + gmtime_r(&time_val, &tm); // Unix/SUSv2 +#else + std::tm* tm_p = std::gmtime(&time_val); + if (tm_p == 0) + throw Encoding_Error("time_t_to_tm could not convert"); + tm = *tm_p; +#endif + + return tm; + } + } /** @@ -64,20 +82,7 @@ std::tm time_t_to_tm(u64bit timer) { std::time_t time_val = static_cast<std::time_t>(timer); - std::tm tm; - -#if defined(BOTAN_TARGET_OS_HAS_GMTIME_S) - gmtime_s(&tm, &time_val); // Windows -#elif defined(BOTAN_TARGET_OS_HAS_GMTIME_R) - gmtime_r(&time_val, &tm); // Unix/SUSv2 -#else - std::tm* tm_p = std::gmtime(&time_val); - if (tm_p == 0) - throw Encoding_Error("time_t_to_tm could not convert"); - tm = *tm_p; -#endif - - return tm; + return do_gmtime(time_val); } u64bit get_nanoseconds_clock() |