00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _TIMEVAL_H
00011 #define _TIMEVAL_H
00012
00013 #ifdef _WIN32
00014
00015 #define WIN32_LEAN_AND_MEAN
00016 #include <winsock2.h>
00017 #include <time.h>
00018
00019 #if defined(_MSC_VER) || defined(__BORLANDC__)
00020 #define EPOCHFILETIME (116444736000000000i64)
00021 #else
00022 #define EPOCHFILETIME (116444736000000000LL)
00023 #endif
00024
00025 struct timezone {
00026 int tz_minuteswest;
00027 int tz_dsttime;
00028 };
00029
00030 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00031 {
00032 FILETIME ft;
00033 LARGE_INTEGER li;
00034 __int64 t;
00035 static int tzflag;
00036
00037 if (tv)
00038 {
00039 GetSystemTimeAsFileTime(&ft);
00040 li.LowPart = ft.dwLowDateTime;
00041 li.HighPart = ft.dwHighDateTime;
00042 t = li.QuadPart;
00043 t -= EPOCHFILETIME;
00044 t /= 10;
00045 tv->tv_sec = (long)(t / 1000000);
00046 tv->tv_usec = (long)(t % 1000000);
00047 }
00048
00049 if (tz)
00050 {
00051 if (!tzflag)
00052 {
00053 _tzset();
00054 tzflag++;
00055 }
00056 tz->tz_minuteswest = _timezone / 60;
00057 tz->tz_dsttime = _daylight;
00058 }
00059
00060 return 0;
00061 }
00062
00063 #else
00064
00065 #include <sys/time.h>
00066
00067 #endif
00068
00069 #endif