diff options
author | nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> | 2025-05-17 21:22:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-17 21:22:15 +0200 |
commit | db953eaf0b7b49e84ee3c556e3e4b974b3ebbb38 (patch) | |
tree | d0a9f6dd598dc30c60dcdda49f117198251eeeb5 | |
parent | 664f3d6a1fadcb3a51dd566f8cbc5d93bf44cc07 (diff) | |
parent | 43b0be8e887bd128924dfcfa766d7b080cba898f (diff) |
Merge pull request #1468 from dbeinder/fix-win32-timeorigin/testingorigin/HEAD
Fixed Win32 gettimeofday implementation
-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) { |