| Revision: | 2.3 |
| Committed: | Sun Mar 6 01:13:17 2016 UTC (9 years, 7 months ago) by schorsch |
| Content type: | text/plain |
| Branch: | MAIN |
| CVS Tags: | rad5R4, rad5R2, rad5R3, rad5R1, rad6R0, HEAD |
| Changes since 2.2: | +1 -1 lines |
| Log Message: | Prepare for SCons build on Win32 and Win64 |
| # | 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 | extern time_t timegm(struct tm *tm); |
| 13 | |
| 14 | #if defined(_WIN32) || defined(_WIN64) |
| 15 | static char * |
| 16 | setGMT() |
| 17 | { |
| 18 | static time_t prevTZ; |
| 19 | prevTZ = _timezone; |
| 20 | _timezone = 0; |
| 21 | return (char *)&prevTZ; |
| 22 | } |
| 23 | static void |
| 24 | resetTZ(char *cp) |
| 25 | { |
| 26 | _timezone = *(time_t *)cp; |
| 27 | } |
| 28 | #else |
| 29 | static char * |
| 30 | setGMT() |
| 31 | { |
| 32 | char *tz = getenv("TZ"); |
| 33 | setenv("TZ", "", 1); |
| 34 | tzset(); |
| 35 | return tz; |
| 36 | } |
| 37 | static void |
| 38 | resetTZ(char *tz) |
| 39 | { |
| 40 | if (tz) |
| 41 | setenv("TZ", tz, 1); |
| 42 | else |
| 43 | unsetenv("TZ"); |
| 44 | tzset(); |
| 45 | } |
| 46 | #endif |
| 47 | |
| 48 | /* Convert GMT to UTC seconds from the epoch */ |
| 49 | time_t |
| 50 | timegm(struct tm *tm) |
| 51 | { |
| 52 | time_t ret; |
| 53 | char *tz; |
| 54 | |
| 55 | tz = setGMT(); |
| 56 | ret = mktime(tm); |
| 57 | resetTZ(tz); |
| 58 | return(ret); |
| 59 | } |