summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2018-12-12 21:28:54 +0200
committerArnold D. Robbins <arnold@skeeve.com>2018-12-12 21:28:54 +0200
commitd96d8fc0e8d06705127d0374f505ca4958124103 (patch)
tree8454121b7425e899c916a615e594136e79f35b49
parent34622512479581e773239909c5ad8c3d8fd5d7b8 (diff)
parentd5d60a503f6de8866be843b40fe6de7c20a0f3a0 (diff)
downloadgawk-d96d8fc0e8d06705127d0374f505ca4958124103.tar.gz
Merge branch 'gawk-4.2-stable'
-rwxr-xr-xChangeLog8
-rw-r--r--builtin.c30
-rw-r--r--configh.in3
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac2
-rw-r--r--missing_d/ChangeLog4
-rw-r--r--missing_d/timegm.c29
-rw-r--r--protos.h4
-rw-r--r--replace.c4
9 files changed, 55 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 8769502f..c7dd31bd 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-12-12 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * configure.ac (AC_CHECK_FUNCS): Check for timegm.
+ * builtin.c (mktime_tz): Remove function; we will use timegm instead.
+ (do_mktime): Replace 'mktime_tz(& then, "UTC+0")' with 'timegm(& then)'.
+ * protos.h (timegm): Add timegm proto on systems lacking it.
+ * replace.c (timegm): Include missing_d/timegm.c if needed.
+
2018-12-06 Arnold D. Robbins <arnold@skeeve.com>
* configure.ac: Add -ggdb3 to CFLAGS if developing and remove
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);
}
diff --git a/configh.in b/configh.in
index 269b9aa6..68ea91aa 100644
--- a/configh.in
+++ b/configh.in
@@ -273,6 +273,9 @@
/* Define to 1 if you have the <termios.h> header file. */
#undef HAVE_TERMIOS_H
+/* Define to 1 if you have the `timegm' function. */
+#undef HAVE_TIMEGM
+
/* Define to 1 if you have the `tmpfile' function. */
#undef HAVE_TMPFILE
diff --git a/configure b/configure
index 14afbbc6..c9ae8229 100755
--- a/configure
+++ b/configure
@@ -9952,7 +9952,7 @@ for ac_func in __etoa_l atexit btowc fmod gai_strerror \
memset_ulong mkstemp posix_openpt setenv setlocale setsid sigprocmask \
snprintf strchr \
strerror strftime strcasecmp strncasecmp strcoll strtod strtoul \
- system tmpfile towlower towupper tzset usleep waitpid wcrtomb \
+ system timegm tmpfile towlower towupper tzset usleep waitpid wcrtomb \
wcscoll wctype
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
diff --git a/configure.ac b/configure.ac
index 0a57d657..fe89e96d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -296,7 +296,7 @@ AC_CHECK_FUNCS(__etoa_l atexit btowc fmod gai_strerror \
memset_ulong mkstemp posix_openpt setenv setlocale setsid sigprocmask \
snprintf strchr \
strerror strftime strcasecmp strncasecmp strcoll strtod strtoul \
- system tmpfile towlower towupper tzset usleep waitpid wcrtomb \
+ system timegm tmpfile towlower towupper tzset usleep waitpid wcrtomb \
wcscoll wctype)
dnl this check is for both mbrtowc and the mbstate_t type, which is good
AC_FUNC_MBRTOWC
diff --git a/missing_d/ChangeLog b/missing_d/ChangeLog
index 1969f52e..9fd121a3 100644
--- a/missing_d/ChangeLog
+++ b/missing_d/ChangeLog
@@ -1,3 +1,7 @@
+2018-12-12 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * timegm.c: New file implementing timegm.
+
2018-10-03 Arnold D. Robbins <arnold@skeeve.com>
* intprops.h, verify.h: Removed. The copy in ../support is
diff --git a/missing_d/timegm.c b/missing_d/timegm.c
new file mode 100644
index 00000000..f7b780de
--- /dev/null
+++ b/missing_d/timegm.c
@@ -0,0 +1,29 @@
+#include <time.h>
+#include <stdlib.h>
+
+static time_t
+timegm(struct tm *tm)
+{
+ time_t ret;
+ char *tz = getenv("TZ");
+ const char *tzreq = "UTC+0"; /* more portable than ""? */
+
+ 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;
+}
diff --git a/protos.h b/protos.h
index 5693a43b..4dd4a221 100644
--- a/protos.h
+++ b/protos.h
@@ -129,6 +129,10 @@ extern void tzset();
extern time_t mktime(struct tm *tp);
#endif
+#ifndef HAVE_TIMEGM
+extern time_t timegm(struct tm *);
+#endif
+
#ifndef HAVE_SNPRINTF
extern int snprintf(char *restrict buf, size_t len, const char *restrict fmt, ...);
#endif
diff --git a/replace.c b/replace.c
index db7f0893..ae069f5b 100644
--- a/replace.c
+++ b/replace.c
@@ -91,6 +91,10 @@
#include "missing_d/mktime.c"
#endif /* HAVE_MKTIME */
+#ifndef HAVE_TIMEGM
+#include "missing_d/timegm.c"
+#endif /* HAVE_TIMEGM */
+
#ifndef HAVE_SNPRINTF
#include "missing_d/snprintf.c"
#endif