diff options
author | lloyd <[email protected]> | 2009-12-24 21:42:00 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-12-24 21:42:00 +0000 |
commit | b44a323d2503d0f0e30d3e58b91488efda88b397 (patch) | |
tree | bf53ed9e94029709fe8cb136956730d830bcaaa1 /src | |
parent | 8e0c38eff91fc6c3df5cc0104704baa75149898e (diff) | |
parent | 986ca995a1a8705cf4231345b44fc4617322e971 (diff) |
propagate from branch 'net.randombit.botan' (head d2ed6f8447671a5a6ce2df0053e0d69bb22ae1ac)
to branch 'net.randombit.botan.c++0x' (head cb3a496f342feba900b1a2901ed87565602bc1f6)
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/time.cpp | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/src/utils/time.cpp b/src/utils/time.cpp index db8055d9f..39c9dd49d 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -49,13 +49,20 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) std::tm do_gmtime(time_t time_val) { - // Race condition: std::gmtime is not assured thread safe, - // and C++ does not include gmtime_r. Use a mutex here? + 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("calendar_value could not convert with gmtime"); - return *tm_p; + throw Encoding_Error("time_t_to_tm could not convert"); + tm = *tm_p; +#endif + + return tm; } } @@ -68,34 +75,14 @@ calendar_point calendar_value( { std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point)); -<<<<<<< variant A - std::tm tm; + std::tm tm = do_gmtime(time_val); -#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; ->>>>>>> variant B return calendar_point(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); -####### Ancestor - std::tm* tm_p = std::gmtime(&time_val); - if (tm_p == 0) - throw Encoding_Error("time_t_to_tm could not convert"); - return (*tm_p); -======= end } u64bit get_nanoseconds_clock() |