2 dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
11 # Redefine AC_FUNC_MKTIME, to fix a bug in Autoconf 2.57 and earlier.
12 # This redefinition can be removed once a new version of Autoconf comes out.
13 # The redefinition is taken from
14 # <http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/autoconf/autoconf/lib/autoconf/functions.m4?rev=1.78>.
17 AC_DEFUN([AC_FUNC_MKTIME],
18 [AC_REQUIRE([AC_HEADER_TIME])dnl
19 AC_CHECK_HEADERS(stdlib.h sys/time.h unistd.h)
21 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
22 [AC_RUN_IFELSE([AC_LANG_SOURCE(
23 [[/* Test program from Paul Eggert and Tony Leneis. */
24 #if TIME_WITH_SYS_TIME
25 # include <sys/time.h>
29 # include <sys/time.h>
44 # define alarm(X) /* empty */
47 /* Work around redefinition to rpl_putenv by other config tests. */
50 static time_t time_t_max;
51 static time_t time_t_min;
53 /* Values we'll use to set the TZ environment variable. */
54 static char *tz_strings[] = {
55 (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)
99 mktime_test1 ((time_t) (time_t_max - now));
100 mktime_test1 ((time_t) (time_t_min + now));
106 /* Based on code from Ariel Faigon. */
116 if (tm.tm_mon != 2 || tm.tm_mday != 31)
126 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
128 if (now != (time_t) -1)
130 struct tm *lt = localtime (&now);
132 && lt->tm_year == tm.tm_year
133 && lt->tm_mon == tm.tm_mon
134 && lt->tm_mday == tm.tm_mday
135 && lt->tm_hour == tm.tm_hour
136 && lt->tm_min == tm.tm_min
137 && lt->tm_sec == tm.tm_sec
138 && lt->tm_yday == tm.tm_yday
139 && lt->tm_wday == tm.tm_wday
140 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
141 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
152 /* This test makes some buggy mktime implementations loop.
153 Give up after 60 seconds; a mktime slower than that
154 isn't worth using anyway. */
157 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
161 for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2)
163 delta = time_t_max / 997; /* a suitable prime number */
164 for (i = 0; i < N_STRINGS; i++)
167 putenv (tz_strings[i]);
169 for (t = 0; t <= time_t_max - delta; t += delta)
171 mktime_test ((time_t) 1);
172 mktime_test ((time_t) (60 * 60));
173 mktime_test ((time_t) (60 * 60 * 24));
175 for (j = 1; 0 < j; j *= 2)
177 bigtime_test (j - 1);
180 spring_forward_gap ();
183 [ac_cv_func_working_mktime=yes],
184 [ac_cv_func_working_mktime=no],
185 [ac_cv_func_working_mktime=no])])
186 if test $ac_cv_func_working_mktime = no; then
191 AC_DEFUN([gl_FUNC_MKTIME],
193 AC_REQUIRE([AC_FUNC_MKTIME])
194 if test $ac_cv_func_working_mktime = no; then
195 AC_DEFINE(mktime, rpl_mktime,
196 [Define to rpl_mktime if the replacement function should be used.])
201 # Prerequisites of lib/mktime.c.
202 AC_DEFUN([gl_PREREQ_MKTIME], [:])