Skip to content

Commit 63477bc

Browse files
Merge pull request #6733 from gojimmypi/windows-gettime_secs
implement gettime_secs for Windows (_MSC_VER) in tests/api.c
2 parents f9c2a86 + bba9add commit 63477bc

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

tests/api.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66471,12 +66471,28 @@ static const char* apitest_res_string(int res)
6647166471

6647266472
#ifndef WOLFSSL_UNIT_TEST_NO_TIMING
6647366473
static double gettime_secs(void)
66474-
{
66475-
struct timeval tv;
66476-
LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
66474+
#if defined(_MSC_VER) && defined(_WIN32)
66475+
{
66476+
/* there's no gettimeofday for Windows, so we'll use system time */
66477+
#define EPOCH_DIFF 11644473600LL
66478+
FILETIME currentFileTime;
66479+
GetSystemTimePreciseAsFileTime(&currentFileTime);
6647766480

66478-
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
66479-
}
66481+
ULARGE_INTEGER uli = { 0, 0 };
66482+
uli.LowPart = currentFileTime.dwLowDateTime;
66483+
uli.HighPart = currentFileTime.dwHighDateTime;
66484+
66485+
/* Convert to seconds since Unix epoch */
66486+
return (double)((uli.QuadPart - (EPOCH_DIFF * 10000000)) / 10000000.0);
66487+
}
66488+
#else
66489+
{
66490+
struct timeval tv;
66491+
LIBCALL_CHECK_RET(gettimeofday(&tv, 0));
66492+
66493+
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
66494+
}
66495+
#endif
6648066496
#endif
6648166497

6648266498
int ApiTest(void)

0 commit comments

Comments
 (0)