00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _TIMEVAL_H
00018 #define _TIMEVAL_H
00019
00020 #ifndef WIN32_LEAN_AND_MEAN
00021 #define WIN32_LEAN_AND_MEAN
00022 #endif
00023
00024 #include <winsock2.h>
00025 #include <time.h>
00026
00027 #if defined(_MSC_VER) || defined(__BORLANDC__)
00028 #define EPOCHFILETIME (116444736000000000i64)
00029 #else
00030 #define EPOCHFILETIME (116444736000000000LL)
00031 #endif
00032
00033 struct timezone {
00034 int tz_minuteswest;
00035 int tz_dsttime;
00036 };
00037
00038
00039 #if !defined(_WIN32_WCE)
00040
00041 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00042 {
00043 FILETIME ft;
00044 LARGE_INTEGER li;
00045 __int64 t;
00046 static int tzflag;
00047
00048 if (tv)
00049 {
00050 GetSystemTimeAsFileTime(&ft);
00051 li.LowPart = ft.dwLowDateTime;
00052 li.HighPart = ft.dwHighDateTime;
00053 t = li.QuadPart;
00054 t -= EPOCHFILETIME;
00055 t /= 10;
00056 tv->tv_sec = (long)(t / 1000000);
00057 tv->tv_usec = (long)(t % 1000000);
00058 }
00059
00060 if (tz)
00061 {
00062 if (!tzflag)
00063 {
00064 _tzset();
00065 tzflag++;
00066 }
00067 tz->tz_minuteswest = _timezone / 60;
00068 tz->tz_dsttime = _daylight;
00069 }
00070
00071 return 0;
00072 }
00073
00074 #else
00075
00076 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00077 {
00078 SYSTEMTIME st;
00079 FILETIME ft;
00080 LARGE_INTEGER li;
00081 TIME_ZONE_INFORMATION tzi;
00082 __int64 t;
00083 static int tzflag;
00084
00085 if (tv)
00086 {
00087 GetSystemTime(&st);
00088 SystemTimeToFileTime(&st, &ft);
00089 li.LowPart = ft.dwLowDateTime;
00090 li.HighPart = ft.dwHighDateTime;
00091 t = li.QuadPart;
00092 t -= EPOCHFILETIME;
00093 t /= 10;
00094 tv->tv_sec = (long)(t / 1000000);
00095 tv->tv_usec = (long)(t % 1000000);
00096 }
00097
00098 if (tz)
00099 {
00100 GetTimeZoneInformation(&tzi);
00101
00102 tz->tz_minuteswest = tzi.Bias;
00103 if (tzi.StandardDate.wMonth != 0)
00104 {
00105 tz->tz_minuteswest += tzi.StandardBias * 60;
00106 }
00107
00108 if (tzi.DaylightDate.wMonth != 0)
00109 {
00110 tz->tz_dsttime = 1;
00111 }
00112 else
00113 {
00114 tz->tz_dsttime = 0;
00115 }
00116 }
00117
00118 return 0;
00119 }
00120
00121 #endif
00122
00123 #endif