Browse code

Provide a timegm implementation for Solaris 10 and below.

Shawn Webb authored on 2014/03/11 23:42:03
Showing 4 changed files
... ...
@@ -401,6 +401,9 @@
401 401
 /* Define to 1 if you have the <termios.h> header file. */
402 402
 #undef HAVE_TERMIOS_H
403 403
 
404
+/* Define to 1 if you have the `timegm' function. */
405
+#undef HAVE_TIMEGM
406
+
404 407
 /* Define this if uname(2) is POSIX */
405 408
 #undef HAVE_UNAME_SYSCALL
406 409
 
... ...
@@ -15728,6 +15728,18 @@ fi
15728 15728
 done
15729 15729
 
15730 15730
 
15731
+for ac_func in timegm
15732
+do :
15733
+  ac_fn_c_check_func "$LINENO" "timegm" "ac_cv_func_timegm"
15734
+if test "x$ac_cv_func_timegm" = xyes; then :
15735
+  cat >>confdefs.h <<_ACEOF
15736
+#define HAVE_TIMEGM 1
15737
+_ACEOF
15738
+
15739
+fi
15740
+done
15741
+
15742
+
15731 15743
 # Check whether --enable-mempool was given.
15732 15744
 if test "${enable_mempool+set}" = set; then :
15733 15745
   enableval=$enable_mempool; enable_mempool=$enableval
... ...
@@ -59,6 +59,36 @@ char * strptime(const char *buf, const char *fmt, struct tm *tm);
59 59
     #define MIN(x,y) ((x)<(y)?(x):(y))
60 60
 #endif
61 61
 
62
+#if !defined(HAVE_TIMEGM)
63
+/*
64
+ * Solaris 10 and earlier don't have timegm. Provide a portable version of it.
65
+ * This function is from the timegm manpage at http://man7.org/linux/man-pages/man3/timegm.3.html
66
+ */
67
+time_t timegm(struct tm *tm)
68
+{
69
+    time_t ret;
70
+    char *tz;
71
+
72
+    tz = getenv("TZ");
73
+    if (tz)
74
+        tz = strdup(tz);
75
+
76
+    setenv("TZ", "", 1);
77
+    tzset();
78
+
79
+    ret = mktime(tm);
80
+    if (tz) {
81
+        setenv("TZ", tz, 1);
82
+        free(tz);
83
+    } else {
84
+        unsetenv("TZ");
85
+    }
86
+
87
+    tzset();
88
+    return ret;
89
+}
90
+#endif
91
+
62 92
 int cl_initialize_crypto(void)
63 93
 {
64 94
     SSL_load_error_strings();
... ...
@@ -11,3 +11,5 @@ AC_C_FUNC_PAGESIZE
11 11
 AC_C_FUNC_MMAP_ANONYMOUS
12 12
 
13 13
 AC_CHECK_FUNCS([enable_extended_FILE_stdio])
14
+
15
+AC_CHECK_FUNCS([timegm])