GEOS 3.4.2

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

timeval.h
1 /**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Wu Yongwei
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 * Note: This code is in the public domain, see
14 * http://wyw.dcweb.cn/time.htm
15 *
16 **********************************************************************/
17
18 #ifndef GEOS_TIMEVAL_H
19 #define GEOS_TIMEVAL_H
20
21 #ifndef WIN32_LEAN_AND_MEAN
22 #define WIN32_LEAN_AND_MEAN
23 #endif
24
25 #include <winsock2.h>
26 #include <time.h>
27
28 #if defined(_MSC_VER) || defined(__BORLANDC__)
29 #define EPOCHFILETIME (116444736000000000i64)
30 #else
31 #define EPOCHFILETIME (116444736000000000LL)
32 #endif
33
34 struct timezone {
35 int tz_minuteswest; /* minutes W of Greenwich */
36 int tz_dsttime; /* type of dst correction */
37 };
38
39
40 #if !defined(_WIN32_WCE)
41
42 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
43 {
44 FILETIME ft;
45 LARGE_INTEGER li;
46 __int64 t;
47 static int tzflag;
48
49 if (tv)
50 {
51 GetSystemTimeAsFileTime(&ft);
52 li.LowPart = ft.dwLowDateTime;
53 li.HighPart = ft.dwHighDateTime;
54 t = li.QuadPart; /* In 100-nanosecond intervals */
55 t -= EPOCHFILETIME; /* Offset to the Epoch time */
56 t /= 10; /* In microseconds */
57 tv->tv_sec = (long)(t / 1000000);
58 tv->tv_usec = (long)(t % 1000000);
59 }
60
61 if (tz)
62 {
63 if (!tzflag)
64 {
65 _tzset();
66 tzflag++;
67 }
68 tz->tz_minuteswest = _timezone / 60;
69 tz->tz_dsttime = _daylight;
70 }
71
72 return 0;
73 }
74
75 #else
76
77 __inline int gettimeofday(struct timeval *tv, struct timezone *tz)
78 {
79 SYSTEMTIME st;
80 FILETIME ft;
81 LARGE_INTEGER li;
82 TIME_ZONE_INFORMATION tzi;
83 __int64 t;
84 static int tzflag;
85
86 if (tv)
87 {
88 GetSystemTime(&st);
89 SystemTimeToFileTime(&st, &ft);
90 li.LowPart = ft.dwLowDateTime;
91 li.HighPart = ft.dwHighDateTime;
92 t = li.QuadPart; /* In 100-nanosecond intervals */
93 t -= EPOCHFILETIME; /* Offset to the Epoch time */
94 t /= 10; /* In microseconds */
95 tv->tv_sec = (long)(t / 1000000);
96 tv->tv_usec = (long)(t % 1000000);
97 }
98
99 if (tz)
100 {
101 GetTimeZoneInformation(&tzi);
102
103 tz->tz_minuteswest = tzi.Bias;
104 if (tzi.StandardDate.wMonth != 0)
105 {
106 tz->tz_minuteswest += tzi.StandardBias * 60;
107 }
108
109 if (tzi.DaylightDate.wMonth != 0)
110 {
111 tz->tz_dsttime = 1;
112 }
113 else
114 {
115 tz->tz_dsttime = 0;
116 }
117 }
118
119 return 0;
120 }
121
122 #endif /* _WIN32_WCE */
123
124 #endif /* GEOS_TIMEVAL_H */