aboutsummaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2018-12-12 14:08:15 -0500
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2018-12-12 14:08:15 -0500
commitd5d60a503f6de8866be843b40fe6de7c20a0f3a0 (patch)
tree90a217238b5b5c08536829c177ccaf339b1a13c3 /builtin.c
parentc856f5c96f88cc8a5aacf6ee90e92ed80bd8c3ba (diff)
downloadegawk-d5d60a503f6de8866be843b40fe6de7c20a0f3a0.tar.gz
egawk-d5d60a503f6de8866be843b40fe6de7c20a0f3a0.tar.bz2
egawk-d5d60a503f6de8866be843b40fe6de7c20a0f3a0.zip
Speed up UTC mktime by using library timegm if available instead of our slow implementation.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c30
1 files changed, 1 insertions, 29 deletions
diff --git a/builtin.c b/builtin.c
index d7b2337e..f2d31059 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2096,34 +2096,6 @@ do_systime(int nargs ATTRIBUTE_UNUSED)
return make_number((AWKNUM) lclock);
}
-/* mktime_tz --- based on Linux timegm man page */
-
-static time_t
-mktime_tz(struct tm *tm, const char *tzreq)
-{
- time_t ret;
- char *tz = getenv("TZ");
-
- if (tz)
- tz = estrdup(tz, strlen(tz));
- if (setenv("TZ", tzreq, 1) < 0) {
- warning(_("setenv(TZ, %s) failed (%s)"), tzreq, strerror(errno));
- return -1;
- }
- tzset();
- ret = mktime(tm);
- if (tz) {
- if (setenv("TZ", tz, 1) < 0)
- fatal(_("setenv(TZ, %s) restoration failed (%s)"), tz, strerror(errno));
- free(tz);
- } else {
- if (unsetenv("TZ") < 0)
- fatal(_("unsetenv(TZ) failed (%s)"), strerror(errno));
- }
- tzset();
- return ret;
-}
-
/* do_mktime --- turn a time string into a timestamp */
NODE *
@@ -2184,7 +2156,7 @@ do_mktime(int nargs)
then.tm_year = year - 1900;
then.tm_isdst = dst;
- then_stamp = (do_gmt ? mktime_tz(& then, "UTC+0") : mktime(& then));
+ then_stamp = (do_gmt ? timegm(& then) : mktime(& then));
return make_number((AWKNUM) then_stamp);
}