2 dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
9 dnl $MirOS: contrib/hosted/tg/deb/cvs/m4/mktime.m4,v 1.2 2013/06/26 19:45:59 tg Exp $
10 dnl Test program updated to git faefb77009239f82ac2f77ac0c10d71d4f38af07
12 # Redefine AC_FUNC_MKTIME, to fix a bug in Autoconf 2.57 and earlier.
13 # This redefinition can be removed once a new version of Autoconf comes out.
14 # The redefinition is taken from
15 # <http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/autoconf/autoconf/lib/autoconf/functions.m4?rev=1.78>.
18 AC_DEFUN([AC_FUNC_MKTIME],
19 [AC_REQUIRE([AC_HEADER_TIME])dnl
20 AC_CHECK_HEADERS(stdlib.h sys/time.h unistd.h)
22 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
23 [AC_RUN_IFELSE([AC_LANG_SOURCE(
24 [[/* Test program from Paul Eggert and Tony Leneis. */
37 /* Work around redefinition to rpl_putenv by other config tests. */
40 static time_t time_t_max;
41 static time_t time_t_min;
43 /* Values we'll use to set the TZ environment variable. */
44 static char *tz_strings[] = {
45 (char *) 0, "TZ=GMT0", "TZ=JST-9",
46 "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
48 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
50 /* Return 0 if mktime fails to convert a date in the spring-forward gap.
51 Based on a problem report from Andreas Jaeger. */
55 /* glibc (up to about 1998-10-07) failed this test. */
58 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
59 instead of "TZ=America/Vancouver" in order to detect the bug even
60 on systems that don't support the Olson extension, or don't have the
61 full zoneinfo tables installed. */
62 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
71 return mktime (&tm) != (time_t) -1;
75 mktime_test1 (time_t now)
78 return ! (lt = localtime (&now)) || mktime (lt) == now;
82 mktime_test (time_t now)
84 return (mktime_test1 (now)
85 && mktime_test1 ((time_t) (time_t_max - now))
86 && mktime_test1 ((time_t) (time_t_min + now)));
92 /* Based on code from Ariel Faigon. */
102 return tm.tm_mon == 2 && tm.tm_mday == 31;
110 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
112 if (now != (time_t) -1)
114 struct tm *lt = localtime (&now);
116 && lt->tm_year == tm.tm_year
117 && lt->tm_mon == tm.tm_mon
118 && lt->tm_mday == tm.tm_mday
119 && lt->tm_hour == tm.tm_hour
120 && lt->tm_min == tm.tm_min
121 && lt->tm_sec == tm.tm_sec
122 && lt->tm_yday == tm.tm_yday
123 && lt->tm_wday == tm.tm_wday
124 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
125 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
134 /* The correct answer for 2050-02-01 00:00:00 in Pacific time,
135 ignoring leap seconds. */
136 unsigned long int answer = 2527315200UL;
140 tm.tm_year = 2050 - 1900;
143 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
146 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
147 instead of "TZ=America/Vancouver" in order to detect the bug even
148 on systems that don't support the Olson extension, or don't have the
149 full zoneinfo tables installed. */
150 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
154 /* Check that the result is either a failure, or close enough
155 to the correct answer that we can assume the discrepancy is
156 due to leap seconds. */
157 return (t == (time_t) -1
158 || (0 < t && answer - 120 <= t && t <= answer + 120));
167 int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1;
168 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. */
174 signal (SIGALRM, SIG_DFL);
178 time_t_max = (! time_t_signed
180 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1)
182 time_t_min = (! time_t_signed
184 : time_t_signed_magnitude
188 delta = time_t_max / 997; /* a suitable prime number */
189 for (i = 0; i < N_STRINGS; i++)
192 putenv (tz_strings[i]);
194 for (t = 0; t <= time_t_max - delta && (result & 1) == 0; t += delta)
195 if (! mktime_test (t))
197 if ((result & 2) == 0
198 && ! (mktime_test ((time_t) 1)
199 && mktime_test ((time_t) (60 * 60))
200 && mktime_test ((time_t) (60 * 60 * 24))))
203 for (j = 1; (result & 4) == 0; j <<= 1)
205 if (! bigtime_test (j))
210 if ((result & 8) == 0 && ! bigtime_test (INT_MAX))
213 if (! irix_6_4_bug ())
215 if (! spring_forward_gap ())
217 if (! year_2050_test ())
221 [ac_cv_func_working_mktime=yes],
222 [ac_cv_func_working_mktime=no],
223 [ac_cv_func_working_mktime=no])])
224 if test $ac_cv_func_working_mktime = no; then
229 AC_DEFUN([gl_FUNC_MKTIME],
231 AC_REQUIRE([AC_FUNC_MKTIME])
232 if test $ac_cv_func_working_mktime = no; then
233 AC_DEFINE(mktime, rpl_mktime,
234 [Define to rpl_mktime if the replacement function should be used.])
239 # Prerequisites of lib/mktime.c.
240 AC_DEFUN([gl_PREREQ_MKTIME], [:])