summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2017-05-21 01:57:55 -0500
committerNicolas Williams <nico@cryptonector.com>2017-05-21 01:57:55 -0500
commit1900c7bcac76777782505c89a032c18a65fcc487 (patch)
tree7000a7be58e1aa72042d167f9c4a9c624adde296
parent578d536233b62884764b3c5c6cd42077958d6a49 (diff)
Add private my_timegm()
-rw-r--r--src/builtin.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/builtin.c b/src/builtin.c
index e785944c..4ce33ca8 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1193,10 +1193,22 @@ static jv tm2jv(struct tm *tm) {
*
* 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
return timegm(tm);
#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);
if (t == (time_t)-1)
return t;
@@ -1207,7 +1219,6 @@ static time_t my_mktime(struct tm *tm) {
#else
return (time_t)-2; /* Not supported */
#endif
-#endif /* !HAVE_TIMEGM */
}
#ifdef HAVE_STRPTIME