GEOS 3.3.4

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

- File List

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