diff options
-rw-r--r-- | src/win32/sys_time.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/win32/sys_time.c b/src/win32/sys_time.c index 0ce38fe..95c8c9f 100644 --- a/src/win32/sys_time.c +++ b/src/win32/sys_time.c @@ -6,7 +6,7 @@ #include <time.h> -/* Simple gettimeofday implementation without converting Windows time to Linux time */ +/* Simple gettimeofday implementation */ int32_t gettimeofday(struct timeval *tv, struct timezone *tz) { FILETIME ftime; ULARGE_INTEGER ulint; @@ -17,8 +17,10 @@ int32_t gettimeofday(struct timeval *tv, struct timezone *tz) { ulint.LowPart = ftime.dwLowDateTime; ulint.HighPart = ftime.dwHighDateTime; - tv->tv_sec = (int32_t) (ulint.QuadPart / 10000000L); - tv->tv_usec = (int32_t) (ulint.QuadPart % 10000000L); + ulint.QuadPart -= 116444736000000000LL; // shift base to unix epoch + ulint.QuadPart /= 10LL; // 100ns ticks to microseconds + tv->tv_sec = (int32_t) (ulint.QuadPart / 1000000LL); + tv->tv_usec = (int32_t) (ulint.QuadPart % 1000000LL); } if(NULL != tz) { |