1 /* XXX NEED Copyright info */
2 #include <wintirpc.h>
3 #include <time.h>
4 
5 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
6   #define DELTA_EPOCH_IN_MICROSECS  11644473600000000Ui64
7 #else
8   #define DELTA_EPOCH_IN_MICROSECS  11644473600000000ULL
9 #endif
10 
gettimeofday(struct timeval * tv,struct timezone * tz)11 int gettimeofday(struct timeval *tv, struct timezone *tz)
12 {
13   FILETIME ft;
14   unsigned __int64 tmpres = 0;
15   static int tzflag;
16 
17   if (NULL != tv)
18   {
19     GetSystemTimeAsFileTime(&ft);
20 
21     tmpres |= ft.dwHighDateTime;
22     tmpres <<= 32;
23     tmpres |= ft.dwLowDateTime;
24 
25     /*converting file time to unix epoch*/
26     tmpres /= 10;  /*convert into microseconds*/
27     tmpres -= DELTA_EPOCH_IN_MICROSECS;
28     tv->tv_sec = (long)(tmpres / 1000000UL);
29     tv->tv_usec = (long)(tmpres % 1000000UL);
30   }
31 
32   if (NULL != tz)
33   {
34     if (!tzflag)
35     {
36       _tzset();
37       tzflag++;
38     }
39     tz->tz_minuteswest = _timezone / 60;
40     tz->tz_dsttime = _daylight;
41   }
42 
43   return 0;
44 }
45