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 <windows.h>
00017 #include <time.h>
00018
00019 #ifndef __GNUC__
00020 #define EPOCHFILETIME (116444736000000000i64)
00021 #else
00022 #define EPOCHFILETIME (116444736000000000LL)
00023 #endif
00024
00025 struct timeval {
00026 long tv_sec;
00027 long tv_usec;
00028 };
00029
00030 struct timezone {
00031 int tz_minuteswest;
00032 int tz_dsttime;
00033 };
00034
00035 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
00036 {
00037 FILETIME ft;
00038 LARGE_INTEGER li;
00039 __int64 t;
00040 static int tzflag;
00041
00042 if (tv)
00043 {
00044 GetSystemTimeAsFileTime(&ft);
00045 li.LowPart = ft.dwLowDateTime;
00046 li.HighPart = ft.dwHighDateTime;
00047 t = li.QuadPart;
00048 t -= EPOCHFILETIME;
00049 t /= 10;
00050 tv->tv_sec = (long)(t / 1000000);
00051 tv->tv_usec = (long)(t % 1000000);
00052 }
00053
00054 if (tz)
00055 {
00056 if (!tzflag)
00057 {
00058 _tzset();
00059 tzflag++;
00060 }
00061 tz->tz_minuteswest = _timezone / 60;
00062 tz->tz_dsttime = _daylight;
00063 }
00064
00065 return 0;
00066 }
00067
00068 #else
00069
00070 #include <sys/time.h>
00071
00072 #endif
00073
00074 #endif