2013-02-28 09:18:38 +08:00
|
|
|
#include <time.h>
|
2015-10-01 12:25:05 +03:00
|
|
|
#include <windows.h> //I've omitted context line
|
2013-02-28 09:22:38 +08:00
|
|
|
|
2015-10-23 08:10:55 +02:00
|
|
|
#include "gettimeofday.h"
|
2013-02-28 09:22:38 +08:00
|
|
|
|
2011-03-10 18:19:10 +00:00
|
|
|
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
|
|
|
{
|
2013-02-28 09:22:38 +08:00
|
|
|
FILETIME ft;
|
|
|
|
unsigned __int64 tmpres = 0;
|
|
|
|
static int tzflag;
|
|
|
|
|
|
|
|
if (NULL != tv) {
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
|
|
|
|
tmpres |= ft.dwHighDateTime;
|
|
|
|
tmpres <<= 32;
|
|
|
|
tmpres |= ft.dwLowDateTime;
|
|
|
|
|
|
|
|
/*converting file time to unix epoch*/
|
|
|
|
tmpres /= 10; /*convert into microseconds*/
|
2013-03-05 08:41:47 +08:00
|
|
|
tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
2013-02-28 09:22:38 +08:00
|
|
|
tv->tv_sec = (long)(tmpres / 1000000UL);
|
|
|
|
tv->tv_usec = (long)(tmpres % 1000000UL);
|
2011-03-10 18:19:10 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 09:22:38 +08:00
|
|
|
if (NULL != tz) {
|
|
|
|
if (!tzflag) {
|
|
|
|
_tzset();
|
|
|
|
tzflag++;
|
|
|
|
}
|
|
|
|
tz->tz_minuteswest = _timezone / 60;
|
|
|
|
tz->tz_dsttime = _daylight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-03-10 18:19:10 +00:00
|
|
|
}
|