| Revision: | 2.2 |
| Committed: | Wed Jun 2 15:58:30 2010 UTC (15 years, 4 months ago) by greg |
| Content type: | text/plain |
| Branch: | MAIN |
| CVS Tags: | rad5R0, rad4R2, rad4R1, rad4R2P1, rad4R2P2 |
| Changes since 2.1: | +6 -4 lines |
| Log Message: | Fixes to MINGW build |
| # | User | Rev | Content |
|---|---|---|---|
| 1 | greg | 2.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 | greg | 2.2 | extern time_t timegm(struct tm *tm); |
| 13 | |||
| 14 | greg | 2.1 | #ifdef _WIN32 |
| 15 | greg | 2.2 | static char * |
| 16 | greg | 2.1 | setGMT() |
| 17 | { | ||
| 18 | static time_t prevTZ; | ||
| 19 | prevTZ = _timezone; | ||
| 20 | _timezone = 0; | ||
| 21 | return (char *)&prevTZ; | ||
| 22 | } | ||
| 23 | greg | 2.2 | static void |
| 24 | greg | 2.1 | resetTZ(char *cp) |
| 25 | { | ||
| 26 | _timezone = *(time_t *)cp; | ||
| 27 | } | ||
| 28 | #else | ||
| 29 | greg | 2.2 | static char * |
| 30 | greg | 2.1 | setGMT() |
| 31 | { | ||
| 32 | char *tz = getenv("TZ"); | ||
| 33 | setenv("TZ", "", 1); | ||
| 34 | tzset(); | ||
| 35 | return tz; | ||
| 36 | } | ||
| 37 | greg | 2.2 | static void |
| 38 | greg | 2.1 | 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 | } |