| #define FILETIME_1970 11644473600ull /* seconds between 1/1/1601 and 1/1/1970 */
|
| #define HECTONANOSEC_PER_SEC 10000000ull
|
| int getntptimeofday (struct timespec *tp, struct timezone *z)
|
| // struct _timeb timebuffer;
|
| TIME_ZONE_INFORMATION TimeZoneInformation;
|
| if ((tzi = GetTimeZoneInformation(&TimeZoneInformation)) != TIME_ZONE_ID_INVALID) {
|
| z->tz_minuteswest = TimeZoneInformation.Bias;
|
| if (tzi == TIME_ZONE_ID_DAYLIGHT)
|
| GetSystemTimeAsFileTime ((LPFILETIME) &fti); /* 100-nanoseconds since 1-1-1601 */
|
| /* The actual accuracy on XP seems to be 125,000 nanoseconds = 125 microseconds = 0.125 milliseconds */
|
| fti.QuadPart -= FILETIME_1970; /* 100 nano-seconds since 1-1-1970 */
|
| tp->tv_sec = fti.QuadPart / HECTONANOSEC_PER_SEC; /* seconds since 1-1-1970 */
|
| tp->tv_nsec = (long) (fti.QuadPart % HECTONANOSEC_PER_SEC) * 100; /* nanoseconds */
|
| int __cdecl gettimeofday (struct timeval *p, struct timezone *z)
|
| if (getntptimeofday (&tp, z))
|
| p->tv_usec=(tp.tv_nsec/1000);
|