27#ifndef HAVE_GETTIMEOFDAY
40static time_t gtc_base = 0;
41static DWORD gtc_last = 0;
42static time_t last_sec = 0;
43static unsigned int last_msec = 0;
44static int bt_last = 0;
47gettimeofday_calibrate(
void)
49 const time_t t = time(NULL);
50 const DWORD gtc = GetTickCount();
51 gtc_base = t - gtc / 1000;
61gettimeofday(
struct timeval *tv,
void *tz)
63 const DWORD gtc = GetTickCount();
67 const int backtrack_hold_seconds = 10;
72 if (!gtc_base || gtc < gtc_last)
74 gettimeofday_calibrate();
78 sec = gtc_base + gtc / 1000;
89 else if (sec < last_sec)
94 if (sec > last_sec - backtrack_hold_seconds)
103 tv->tv_sec = (long)sec;
104 tv->tv_usec = (last_msec = msec) * 1000;
108 gettimeofday_calibrate();
120gettimeofday(
struct timeval *tv,
void *tz)
123 tv->tv_sec = time(NULL);