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