File indexing completed on 2024-05-12 16:36:59
0001 #ifndef QUIRK_SYS_TIME_H 0002 #define QUIRK_SYS_TIME_H 0003 0004 #include <time.h> 0005 #include <windows.h> 0006 #include <WinSock2.h> 0007 0008 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 0009 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 0010 #else 0011 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 0012 #endif 0013 0014 #ifndef _TIMEZONE_DEFINED /* Matches sys/time.h and mingw32/include/time.h */ 0015 #define _TIMEZONE_DEFINED 0016 struct timezone 0017 { 0018 int tz_minuteswest; /* minutes W of Greenwich */ 0019 int tz_dsttime; /* type of dst correction */ 0020 }; 0021 #endif 0022 0023 static int 0024 gettimeofday(struct timeval * tv, struct timezone * tz) 0025 { 0026 FILETIME ft; 0027 unsigned __int64 tmpres = 0; 0028 static int tzflag; 0029 0030 if (NULL != tv) 0031 { 0032 GetSystemTimeAsFileTime(&ft); 0033 0034 tmpres |= ft.dwHighDateTime; 0035 tmpres <<= 32; 0036 tmpres |= ft.dwLowDateTime; 0037 0038 /*converting file time to unix epoch*/ 0039 tmpres -= DELTA_EPOCH_IN_MICROSECS; 0040 tmpres /= 10; /*convert into microseconds*/ 0041 tv->tv_sec = (long)(tmpres / 1000000UL); 0042 tv->tv_usec = (long)(tmpres % 1000000UL); 0043 } 0044 0045 if (NULL != tz) 0046 { 0047 if (!tzflag) 0048 { 0049 _tzset(); 0050 tzflag++; 0051 } 0052 tz->tz_minuteswest = _timezone / 60; 0053 tz->tz_dsttime = _daylight; 0054 } 0055 0056 return 0; 0057 } 0058 #endif