aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/time.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/time.cpp')
-rw-r--r--src/utils/time.cpp50
1 files changed, 43 insertions, 7 deletions
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index 97804813d..db8055d9f 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -9,21 +9,25 @@
#include <botan/exceptn.h>
#include <ctime>
+#if defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME)
+ #include <windows.h>
+#endif
+
#if defined(BOTAN_TARGET_OS_HAS_GETTIMEOFDAY)
#include <sys/time.h>
#endif
#if defined(BOTAN_TARGET_OS_HAS_CLOCK_GETTIME)
-#ifndef _POSIX_C_SOURCE
- #define _POSIX_C_SOURCE 199309
-#endif
+ #ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199309
+ #endif
-#include <time.h>
+ #include <time.h>
-#ifndef CLOCK_REALTIME
- #define CLOCK_REALTIME 0
-#endif
+ #ifndef CLOCK_REALTIME
+ #define CLOCK_REALTIME 0
+ #endif
#endif
@@ -64,12 +68,34 @@ calendar_point calendar_value(
{
std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point));
+<<<<<<< variant A
+ 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;
+>>>>>>> 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()
@@ -84,6 +110,16 @@ u64bit get_nanoseconds_clock()
::gettimeofday(&tv, 0);
return combine_timers(tv.tv_sec, tv.tv_usec, 1000000);
+#elif defined(BOTAN_TARGET_OS_HAS_WIN32_GET_SYSTEMTIME)
+
+ // Returns time since January 1, 1601 in 100-ns increments
+ ::FILETIME tv;
+ ::GetSystemTimeAsFileTime(&tv);
+ u64bit tstamp = (static_cast<u64bit>(tv.dwHighDateTime) << 32) |
+ tv.dwLowDateTime;
+
+ return (tstamp * 100); // Scale to 1 nanosecond units
+
#else
return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);