aboutsummaryrefslogtreecommitdiffstats
path: root/missing_d
diff options
context:
space:
mode:
Diffstat (limited to 'missing_d')
-rw-r--r--missing_d/ChangeLog4
-rw-r--r--missing_d/timegm.c29
2 files changed, 33 insertions, 0 deletions
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;
+}