From 321f74869afc757fd37f2d2be1e4bb4cdbee5308 Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Fri, 25 Aug 2023 18:30:05 -0700 Subject: [PATCH] implement gettime_secs for Windows (_MSC_VER) in tests/api.c --- tests/api.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/api.c b/tests/api.c index 9579f9076..9b7cd281b 100644 --- a/tests/api.c +++ b/tests/api.c @@ -66255,10 +66255,28 @@ static const char* apitest_res_string(int res) #ifndef WOLFSSL_UNIT_TEST_NO_TIMING static double gettime_secs(void) { - struct timeval tv; - LIBCALL_CHECK_RET(gettimeofday(&tv, 0)); + #if defined(_MSC_VER) && defined(_WIN32) + { + /* there's no gettimeofday for Windows, so we'll use system time */ + #define EPOCH_DIFF 11644473600LL + FILETIME currentFileTime; + GetSystemTimePreciseAsFileTime(¤tFileTime); - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; + ULARGE_INTEGER uli = { 0, 0 }; + uli.LowPart = currentFileTime.dwLowDateTime; + uli.HighPart = currentFileTime.dwHighDateTime; + + /* Convert to seconds since Unix epoch */ + return (double)((uli.QuadPart - EPOCH_DIFF * 10000000) / 10000000); + } + #else + { + struct timeval tv; + LIBCALL_CHECK_RET(gettimeofday(&tv, 0)); + + return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; + } + #endif } #endif