28 #ifndef HAVE_GETTIMEOFDAY
41 static time_t gtc_base = 0;
42 static DWORD gtc_last = 0;
43 static time_t last_sec = 0;
44 static unsigned int last_msec = 0;
45 static int bt_last = 0;
48 gettimeofday_calibrate(
void)
50 const time_t t = time(NULL);
51 const DWORD gtc = GetTickCount();
52 gtc_base = t - gtc/1000;
62 gettimeofday(
struct timeval *tv,
void *tz)
64 const DWORD gtc = GetTickCount();
68 const int backtrack_hold_seconds = 10;
73 if (!gtc_base || gtc < gtc_last)
75 gettimeofday_calibrate();
79 sec = gtc_base + gtc / 1000;
90 else if (sec < last_sec)
95 if (sec > last_sec - backtrack_hold_seconds)
104 tv->tv_sec = (long)sec;
105 tv->tv_usec = (last_msec = msec) * 1000;
109 gettimeofday_calibrate();
121 gettimeofday(
struct timeval *tv,
void *tz)
124 tv->tv_sec = time(NULL);