2 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation,
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
10 # Redefine AC_FUNC_MKTIME, to fix a bug in Autoconf 2.61a and earlier.
11 # This redefinition can be removed once a new version of Autoconf is assumed.
12 # The redefinition is taken from
13 # <http://cvs.sv.gnu.org/viewcvs/*checkout*/autoconf/autoconf/lib/autoconf/functions.m4?rev=1.119>.
16 AC_DEFUN([AC_FUNC_MKTIME],
17 [AC_CHECK_HEADERS_ONCE([unistd.h])
18 AC_CHECK_FUNCS_ONCE([alarm])
19 AC_REQUIRE([gl_MULTIARCH])
20 if test $APPLE_UNIVERSAL_BUILD = 1; then
21 # A universal build on Apple MacOS X platforms.
22 # The test result would be 'yes' in 32-bit mode and 'no' in 64-bit mode.
23 # But we need a configuration result that is valid in both modes.
24 ac_cv_func_working_mktime=no
26 AC_CACHE_CHECK([for working mktime], [ac_cv_func_working_mktime],
27 [AC_RUN_IFELSE([AC_LANG_SOURCE(
28 [[/* Test program from Paul Eggert and Tony Leneis. */
38 # define alarm(X) /* empty */
41 /* Work around redefinition to rpl_putenv by other config tests. */
44 static time_t time_t_max;
45 static time_t time_t_min;
47 /* Values we'll use to set the TZ environment variable. */
48 static char *tz_strings[] = {
49 (char *) 0, "TZ=GMT0", "TZ=JST-9",
50 "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
52 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
54 /* Return 0 if mktime fails to convert a date in the spring-forward gap.
55 Based on a problem report from Andreas Jaeger. */
59 /* glibc (up to about 1998-10-07) failed this test. */
62 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
63 instead of "TZ=America/Vancouver" in order to detect the bug even
64 on systems that don't support the Olson extension, or don't have the
65 full zoneinfo tables installed. */
66 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
75 return mktime (&tm) != (time_t) -1;
79 mktime_test1 (time_t now)
82 return ! (lt = localtime (&now)) || mktime (lt) == now;
86 mktime_test (time_t now)
88 return (mktime_test1 (now)
89 && mktime_test1 ((time_t) (time_t_max - now))
90 && mktime_test1 ((time_t) (time_t_min + now)));
96 /* Based on code from Ariel Faigon. */
106 return tm.tm_mon == 2 && tm.tm_mday == 31;
114 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
116 if (now != (time_t) -1)
118 struct tm *lt = localtime (&now);
120 && lt->tm_year == tm.tm_year
121 && lt->tm_mon == tm.tm_mon
122 && lt->tm_mday == tm.tm_mday
123 && lt->tm_hour == tm.tm_hour
124 && lt->tm_min == tm.tm_min
125 && lt->tm_sec == tm.tm_sec
126 && lt->tm_yday == tm.tm_yday
127 && lt->tm_wday == tm.tm_wday
128 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
129 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
138 /* The correct answer for 2050-02-01 00:00:00 in Pacific time,
139 ignoring leap seconds. */
140 unsigned long int answer = 2527315200UL;
144 tm.tm_year = 2050 - 1900;
147 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
150 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
151 instead of "TZ=America/Vancouver" in order to detect the bug even
152 on systems that don't support the Olson extension, or don't have the
153 full zoneinfo tables installed. */
154 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
158 /* Check that the result is either a failure, or close enough
159 to the correct answer that we can assume the discrepancy is
160 due to leap seconds. */
161 return (t == (time_t) -1
162 || (0 < t && answer - 120 <= t && t <= answer + 120));
171 /* This test makes some buggy mktime implementations loop.
172 Give up after 60 seconds; a mktime slower than that
173 isn't worth using anyway. */
178 t = (time_t_max << 1) + 1;
183 time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max;
185 delta = time_t_max / 997; /* a suitable prime number */
186 for (i = 0; i < N_STRINGS; i++)
189 putenv (tz_strings[i]);
191 for (t = 0; t <= time_t_max - delta; t += delta)
192 if (! mktime_test (t))
194 if (! (mktime_test ((time_t) 1)
195 && mktime_test ((time_t) (60 * 60))
196 && mktime_test ((time_t) (60 * 60 * 24))))
199 for (j = 1; ; j <<= 1)
200 if (! bigtime_test (j))
202 else if (INT_MAX / 2 < j)
204 if (! bigtime_test (INT_MAX))
207 return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());
209 [ac_cv_func_working_mktime=yes],
210 [ac_cv_func_working_mktime=no],
211 [ac_cv_func_working_mktime=no])])
212 if test $ac_cv_func_working_mktime = no; then
217 AC_DEFUN([gl_FUNC_MKTIME],
219 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
221 dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]).
222 if test $ac_cv_func_working_mktime = no; then
230 # Prerequisites of lib/mktime.c.
231 AC_DEFUN([gl_PREREQ_MKTIME],
233 AC_REQUIRE([AC_C_INLINE])