• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <time.h>
2 #include <windows.h> //I've omitted context line
3 
4 #include "gettimeofday.h"
5 
gettimeofday(struct timeval * tv,struct timezone * tz)6 int gettimeofday(struct timeval *tv, struct timezone *tz)
7 {
8 	FILETIME ft;
9 	unsigned __int64 tmpres = 0;
10 	static int tzflag;
11 
12 	if (NULL != tv) {
13 		GetSystemTimeAsFileTime(&ft);
14 
15 		tmpres |= ft.dwHighDateTime;
16 		tmpres <<= 32;
17 		tmpres |= ft.dwLowDateTime;
18 
19 		/*converting file time to unix epoch*/
20 		tmpres /= 10;  /*convert into microseconds*/
21 		tmpres -= DELTA_EPOCH_IN_MICROSECS;
22 		tv->tv_sec = (long)(tmpres / 1000000UL);
23 		tv->tv_usec = (long)(tmpres % 1000000UL);
24 	}
25 
26 	if (NULL != tz) {
27 		if (!tzflag) {
28 			_tzset();
29 			tzflag++;
30 		}
31 		tz->tz_minuteswest = _timezone / 60;
32 		tz->tz_dsttime = _daylight;
33 	}
34 
35 	return 0;
36 }
37