Skip to content

Commit db953ea

Browse files
Merge pull request #1468 from dbeinder/fix-win32-time
Fixed Win32 gettimeofday implementation
2 parents 664f3d6 + 43b0be8 commit db953ea

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/win32/sys_time.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <time.h>
88

9-
/* Simple gettimeofday implementation without converting Windows time to Linux time */
9+
/* Simple gettimeofday implementation */
1010
int32_t gettimeofday(struct timeval *tv, struct timezone *tz) {
1111
FILETIME ftime;
1212
ULARGE_INTEGER ulint;
@@ -17,8 +17,10 @@ int32_t gettimeofday(struct timeval *tv, struct timezone *tz) {
1717
ulint.LowPart = ftime.dwLowDateTime;
1818
ulint.HighPart = ftime.dwHighDateTime;
1919

20-
tv->tv_sec = (int32_t) (ulint.QuadPart / 10000000L);
21-
tv->tv_usec = (int32_t) (ulint.QuadPart % 10000000L);
20+
ulint.QuadPart -= 116444736000000000LL; // shift base to unix epoch
21+
ulint.QuadPart /= 10LL; // 100ns ticks to microseconds
22+
tv->tv_sec = (int32_t) (ulint.QuadPart / 1000000LL);
23+
tv->tv_usec = (int32_t) (ulint.QuadPart % 1000000LL);
2224
}
2325

2426
if(NULL != tz) {

0 commit comments

Comments
 (0)