diff --git a/src/port/gettimeofday.c b/src/port/gettimeofday.c index ab4f491..f4d8393 100644 --- a/src/port/gettimeofday.c +++ b/src/port/gettimeofday.c @@ -35,6 +35,13 @@ static const unsigned __int64 epoch = UINT64CONST(116444736000000000); /* + * FILETIME represents the number of 100-nanosecond intervals since + * January 1, 1601 (UTC). + */ +#define FILETIME_PER_SEC 10000000L +#define FILETIME_PER_USEC 10 + +/* * Both GetSystemTimeAsFileTime and GetSystemTimePreciseAsFileTime share a * signature, so we can just store a pointer to whichever we find. This * is the pointer's type. @@ -98,8 +105,9 @@ gettimeofday(struct timeval * tp, struct timezone * tzp) ularge.LowPart = file_time.dwLowDateTime; ularge.HighPart = file_time.dwHighDateTime; - tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); - tp->tv_usec = (long) (((ularge.QuadPart - epoch) % 10000000L) / 10); + tp->tv_sec = (long) ((ularge.QuadPart - epoch) / FILETIME_PER_SEC); + tp->tv_usec = (long) (((ularge.QuadPart - epoch) % FILETIME_PER_SEC) + / FILETIME_PER_USEC); return 0; }