Revision: | 2.1 |
Committed: | Thu May 27 19:32:12 2010 UTC (14 years, 11 months ago) by greg |
Content type: | text/plain |
Branch: | MAIN |
Log Message: | Changes for MINGW compilation using SCons (thanks to C. Kohler) |
# | Content |
---|---|
1 | /* |
2 | * timegm.c |
3 | * |
4 | * Replacement for missing GNU library function. |
5 | * |
6 | */ |
7 | |
8 | |
9 | #include <time.h> |
10 | #include <stdlib.h> |
11 | |
12 | #ifdef _WIN32 |
13 | char * |
14 | setGMT() |
15 | { |
16 | static time_t prevTZ; |
17 | prevTZ = _timezone; |
18 | _timezone = 0; |
19 | return (char *)&prevTZ; |
20 | } |
21 | void |
22 | resetTZ(char *cp) |
23 | { |
24 | _timezone = *(time_t *)cp; |
25 | } |
26 | #else |
27 | char * |
28 | setGMT() |
29 | { |
30 | char *tz = getenv("TZ"); |
31 | setenv("TZ", "", 1); |
32 | tzset(); |
33 | return tz; |
34 | } |
35 | void |
36 | resetTZ(char *tz) |
37 | { |
38 | if (tz) |
39 | setenv("TZ", tz, 1); |
40 | else |
41 | unsetenv("TZ"); |
42 | tzset(); |
43 | } |
44 | #endif |
45 | |
46 | /* Convert GMT to UTC seconds from the epoch */ |
47 | time_t |
48 | timegm(struct tm *tm) |
49 | { |
50 | time_t ret; |
51 | char *tz; |
52 | |
53 | tz = setGMT(); |
54 | ret = mktime(tm); |
55 | resetTZ(tz); |
56 | return(ret); |
57 | } |