4
dnl A wrapper around AC_FUNC_MKTIME.
6
AC_DEFUN(jm_FUNC_MKTIME,
7
[AC_REQUIRE([AC_FUNC_MKTIME])dnl
9
dnl mktime.c uses localtime_r if it exists. Check for it.
10
AC_CHECK_FUNCS(localtime_r)
12
if test $ac_cv_func_working_mktime = no; then
13
AC_DEFINE_UNQUOTED(mktime, rpl_mktime,
14
[Define to rpl_mktime if the replacement function should be used.])
20
# Stolen from CVS Autoconf. Should be removed once you use Autoconf 2.15.
21
AC_DEFUN(AC_FUNC_MKTIME,
22
[AC_REQUIRE([AC_HEADER_TIME])dnl
23
AC_CHECK_HEADERS(sys/time.h unistd.h)
25
AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
27
[/* Test program from Paul Eggert (eggert@twinsun.com)
28
and Tony Leneis (tony@plaza.ds.adp.com). */
29
#if TIME_WITH_SYS_TIME
30
# include <sys/time.h>
34
# include <sys/time.h>
45
# define alarm(X) /* empty */
48
/* Work around redefinition to rpl_putenv by other config tests. */
51
static time_t time_t_max;
53
/* Values we'll use to set the TZ environment variable. */
54
static const char *const tz_strings[] = {
55
(const char *) 0, "TZ=GMT0", "TZ=JST-9",
56
"TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
58
#define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
60
/* Fail if mktime fails to convert a date in the spring-forward gap.
61
Based on a problem report from Andreas Jaeger. */
65
/* glibc (up to about 1998-10-07) failed this test) */
68
/* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
69
instead of "TZ=America/Vancouver" in order to detect the bug even
70
on systems that don't support the Olson extension, or don't have the
71
full zoneinfo tables installed. */
72
putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
81
if (mktime (&tm) == (time_t)-1)
90
if ((lt = localtime (&now)) && mktime (lt) != now)
92
now = time_t_max - now;
93
if ((lt = localtime (&now)) && mktime (lt) != now)
100
/* Based on code from Ariel Faigon. */
110
if (tm.tm_mon != 2 || tm.tm_mday != 31)
120
tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
122
if (now != (time_t) -1)
124
struct tm *lt = localtime (&now);
126
&& lt->tm_year == tm.tm_year
127
&& lt->tm_mon == tm.tm_mon
128
&& lt->tm_mday == tm.tm_mday
129
&& lt->tm_hour == tm.tm_hour
130
&& lt->tm_min == tm.tm_min
131
&& lt->tm_sec == tm.tm_sec
132
&& lt->tm_yday == tm.tm_yday
133
&& lt->tm_wday == tm.tm_wday
134
&& ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
135
== (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
146
/* This test makes some buggy mktime implementations loop.
147
Give up after 60 seconds; a mktime slower than that
148
isn't worth using anyway. */
151
for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
154
delta = time_t_max / 997; /* a suitable prime number */
155
for (i = 0; i < N_STRINGS; i++)
158
putenv (tz_strings[i]);
160
for (t = 0; t <= time_t_max - delta; t += delta)
162
mktime_test ((time_t) 60 * 60);
163
mktime_test ((time_t) 60 * 60 * 24);
165
for (j = 1; 0 < j; j *= 2)
167
bigtime_test (j - 1);
170
spring_forward_gap ();
173
ac_cv_func_working_mktime=yes, ac_cv_func_working_mktime=no,
174
ac_cv_func_working_mktime=no)])
175
if test $ac_cv_func_working_mktime = no; then
176
LIBOBJS="$LIBOBJS mktime.${ac_objext}"
b'\\ No newline at end of file'