2 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2011 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, because it is no longer maintained in Autoconf.
13 AC_DEFUN([AC_FUNC_MKTIME],
14 [AC_CHECK_HEADERS_ONCE([unistd.h])
15 AC_CHECK_FUNCS_ONCE([alarm])
16 AC_REQUIRE([gl_MULTIARCH])
17 if test $APPLE_UNIVERSAL_BUILD = 1; then
18 # A universal build on Apple MacOS X platforms.
19 # The test result would be 'yes' in 32-bit mode and 'no' in 64-bit mode.
20 # But we need a configuration result that is valid in both modes.
21 ac_cv_func_working_mktime=no
23 AC_CACHE_CHECK([for working mktime], [ac_cv_func_working_mktime],
24 [AC_RUN_IFELSE([AC_LANG_SOURCE(
25 [[/* Test program from Paul Eggert and Tony Leneis. */
35 # define alarm(X) /* empty */
38 /* Work around redefinition to rpl_putenv by other config tests. */
41 static time_t time_t_max;
42 static time_t time_t_min;
44 /* Values we'll use to set the TZ environment variable. */
45 static char *tz_strings[] = {
46 (char *) 0, "TZ=GMT0", "TZ=JST-9",
47 "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
49 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
51 /* Return 0 if mktime fails to convert a date in the spring-forward gap.
52 Based on a problem report from Andreas Jaeger. */
56 /* glibc (up to about 1998-10-07) failed this test. */
59 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
60 instead of "TZ=America/Vancouver" in order to detect the bug even
61 on systems that don't support the Olson extension, or don't have the
62 full zoneinfo tables installed. */
63 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
72 return mktime (&tm) != (time_t) -1;
76 mktime_test1 (time_t now)
79 return ! (lt = localtime (&now)) || mktime (lt) == now;
83 mktime_test (time_t now)
85 return (mktime_test1 (now)
86 && mktime_test1 ((time_t) (time_t_max - now))
87 && mktime_test1 ((time_t) (time_t_min + now)));
93 /* Based on code from Ariel Faigon. */
103 return tm.tm_mon == 2 && tm.tm_mday == 31;
111 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
113 if (now != (time_t) -1)
115 struct tm *lt = localtime (&now);
117 && lt->tm_year == tm.tm_year
118 && lt->tm_mon == tm.tm_mon
119 && lt->tm_mday == tm.tm_mday
120 && lt->tm_hour == tm.tm_hour
121 && lt->tm_min == tm.tm_min
122 && lt->tm_sec == tm.tm_sec
123 && lt->tm_yday == tm.tm_yday
124 && lt->tm_wday == tm.tm_wday
125 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
126 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
135 /* The correct answer for 2050-02-01 00:00:00 in Pacific time,
136 ignoring leap seconds. */
137 unsigned long int answer = 2527315200UL;
141 tm.tm_year = 2050 - 1900;
144 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
147 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
148 instead of "TZ=America/Vancouver" in order to detect the bug even
149 on systems that don't support the Olson extension, or don't have the
150 full zoneinfo tables installed. */
151 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
155 /* Check that the result is either a failure, or close enough
156 to the correct answer that we can assume the discrepancy is
157 due to leap seconds. */
158 return (t == (time_t) -1
159 || (0 < t && answer - 120 <= t && t <= answer + 120));
168 int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1;
169 int time_t_signed = ! ((time_t) 0 < (time_t) -1);
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. */
176 time_t_max = (! time_t_signed
178 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1)
180 time_t_min = (! time_t_signed
182 : time_t_signed_magnitude
186 delta = time_t_max / 997; /* a suitable prime number */
187 for (i = 0; i < N_STRINGS; i++)
190 putenv (tz_strings[i]);
192 for (t = 0; t <= time_t_max - delta; t += delta)
193 if (! mktime_test (t))
195 if (! (mktime_test ((time_t) 1)
196 && mktime_test ((time_t) (60 * 60))
197 && mktime_test ((time_t) (60 * 60 * 24))))
200 for (j = 1; ; j <<= 1)
201 if (! bigtime_test (j))
203 else if (INT_MAX / 2 < j)
205 if (! bigtime_test (INT_MAX))
208 if (! irix_6_4_bug ())
210 if (! spring_forward_gap ())
212 if (! year_2050_test ())
216 [ac_cv_func_working_mktime=yes],
217 [ac_cv_func_working_mktime=no],
218 [ac_cv_func_working_mktime=no])])
219 if test $ac_cv_func_working_mktime = no; then
224 AC_DEFUN([gl_FUNC_MKTIME],
226 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
228 dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]).
229 if test $ac_cv_func_working_mktime = no; then
237 # Prerequisites of lib/mktime.c.
238 AC_DEFUN([gl_PREREQ_MKTIME],
240 AC_REQUIRE([AC_C_INLINE])