GEOS
3.6.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2006 Wu Yongwei 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 00012 * 00013 * Note: This code is in the public domain, see 00014 * http://wyw.dcweb.cn/time.htm 00015 * 00016 **********************************************************************/ 00017 00018 #ifndef GEOS_TIMEVAL_H 00019 #define GEOS_TIMEVAL_H 00020 00021 #if !defined(_WIN32) 00022 #error This header is dedicated to Windows platform only 00023 #endif 00024 00025 #ifndef WIN32_LEAN_AND_MEAN 00026 #define WIN32_LEAN_AND_MEAN 00027 #endif 00028 00029 #ifndef NOMINMAX 00030 #define NOMINMAX 00031 #endif 00032 00033 #ifndef STRICT 00034 #define STRICT 00035 #endif 00036 00037 #include <winsock2.h> 00038 #include <time.h> 00039 00040 #if defined(_MSC_VER) || defined(__BORLANDC__) 00041 #define EPOCHFILETIME (116444736000000000i64) 00042 #else 00043 #define EPOCHFILETIME (116444736000000000LL) 00044 #endif 00045 00046 struct timezone { 00047 int tz_minuteswest; /* minutes W of Greenwich */ 00048 int tz_dsttime; /* type of dst correction */ 00049 }; 00050 00051 00052 #if !defined(_WIN32_WCE) 00053 00054 __inline int gettimeofday(struct timeval *tv, struct timezone *tz) 00055 { 00056 FILETIME ft; 00057 LARGE_INTEGER li; 00058 __int64 t; 00059 static int tzflag; 00060 00061 if (tv) 00062 { 00063 GetSystemTimeAsFileTime(&ft); 00064 li.LowPart = ft.dwLowDateTime; 00065 li.HighPart = ft.dwHighDateTime; 00066 t = li.QuadPart; /* In 100-nanosecond intervals */ 00067 t -= EPOCHFILETIME; /* Offset to the Epoch time */ 00068 t /= 10; /* In microseconds */ 00069 tv->tv_sec = (long)(t / 1000000); 00070 tv->tv_usec = (long)(t % 1000000); 00071 } 00072 00073 if (tz) 00074 { 00075 if (!tzflag) 00076 { 00077 _tzset(); 00078 tzflag++; 00079 } 00080 tz->tz_minuteswest = _timezone / 60; 00081 tz->tz_dsttime = _daylight; 00082 } 00083 00084 return 0; 00085 } 00086 00087 #else 00088 00089 __inline int gettimeofday(struct timeval *tv, struct timezone *tz) 00090 { 00091 SYSTEMTIME st; 00092 FILETIME ft; 00093 LARGE_INTEGER li; 00094 TIME_ZONE_INFORMATION tzi; 00095 __int64 t; 00096 static int tzflag; 00097 00098 if (tv) 00099 { 00100 GetSystemTime(&st); 00101 SystemTimeToFileTime(&st, &ft); 00102 li.LowPart = ft.dwLowDateTime; 00103 li.HighPart = ft.dwHighDateTime; 00104 t = li.QuadPart; /* In 100-nanosecond intervals */ 00105 t -= EPOCHFILETIME; /* Offset to the Epoch time */ 00106 t /= 10; /* In microseconds */ 00107 tv->tv_sec = (long)(t / 1000000); 00108 tv->tv_usec = (long)(t % 1000000); 00109 } 00110 00111 if (tz) 00112 { 00113 GetTimeZoneInformation(&tzi); 00114 00115 tz->tz_minuteswest = tzi.Bias; 00116 if (tzi.StandardDate.wMonth != 0) 00117 { 00118 tz->tz_minuteswest += tzi.StandardBias * 60; 00119 } 00120 00121 if (tzi.DaylightDate.wMonth != 0) 00122 { 00123 tz->tz_dsttime = 1; 00124 } 00125 else 00126 { 00127 tz->tz_dsttime = 0; 00128 } 00129 } 00130 00131 return 0; 00132 } 00133 00134 #endif /* _WIN32_WCE */ 00135 00136 #endif /* GEOS_TIMEVAL_H */