1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Add private my_timegm()

This commit is contained in:
Nicolas Williams
2017-05-21 01:57:55 -05:00
parent 578d536233
commit 1900c7bcac

View File

@ -1193,10 +1193,22 @@ static jv tm2jv(struct tm *tm) {
* *
* Returns (time_t)-2 if mktime()'s side-effects cannot be corrected. * Returns (time_t)-2 if mktime()'s side-effects cannot be corrected.
*/ */
static time_t my_mktime(struct tm *tm) { static time_t my_timegm(struct tm *tm) {
#ifdef HAVE_TIMEGM #ifdef HAVE_TIMEGM
return timegm(tm); return timegm(tm);
#else /* HAVE_TIMEGM */ #else /* HAVE_TIMEGM */
char *tz;
tz = (tz = getenv("TZ")) != NULL ? strdup(tz) : NULL;
if (tz != NULL)
setenv("TZ", "", 1);
time_t t = mktime(tm);
if (tz != NULL)
setenv("TZ", tz, 1);
return t;
#endif /* !HAVE_TIMEGM */
}
static time_t my_mktime(struct tm *tm) {
time_t t = mktime(tm); time_t t = mktime(tm);
if (t == (time_t)-1) if (t == (time_t)-1)
return t; return t;
@ -1207,7 +1219,6 @@ static time_t my_mktime(struct tm *tm) {
#else #else
return (time_t)-2; /* Not supported */ return (time_t)-2; /* Not supported */
#endif #endif
#endif /* !HAVE_TIMEGM */
} }
#ifdef HAVE_STRPTIME #ifdef HAVE_STRPTIME