2
dnl Copyright (C) 2002, 2003, 2005, 2006, 2007 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
# Redefine AC_FUNC_MKTIME, to fix a bug in Autoconf 2.61a and earlier.
10
# This redefinition can be removed once a new version of Autoconf is assumed.
11
# The redefinition is taken from
12
# <http://cvs.sv.gnu.org/viewcvs/*checkout*/autoconf/autoconf/lib/autoconf/functions.m4?rev=1.119>.
15
AC_DEFUN([AC_FUNC_MKTIME],
16
[AC_CHECK_HEADERS_ONCE(unistd.h)
17
AC_CHECK_FUNCS_ONCE(alarm)
18
AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
19
[AC_RUN_IFELSE([AC_LANG_SOURCE(
20
[[/* Test program from Paul Eggert and Tony Leneis. */
30
# define alarm(X) /* empty */
33
/* Work around redefinition to rpl_putenv by other config tests. */
36
static time_t time_t_max;
37
static time_t time_t_min;
39
/* Values we'll use to set the TZ environment variable. */
40
static char *tz_strings[] = {
41
(char *) 0, "TZ=GMT0", "TZ=JST-9",
42
"TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
44
#define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
46
/* Return 0 if mktime fails to convert a date in the spring-forward gap.
47
Based on a problem report from Andreas Jaeger. */
51
/* glibc (up to about 1998-10-07) failed this test. */
54
/* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
55
instead of "TZ=America/Vancouver" in order to detect the bug even
56
on systems that don't support the Olson extension, or don't have the
57
full zoneinfo tables installed. */
58
putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
67
return mktime (&tm) != (time_t) -1;
75
return ! (lt = localtime (&now)) || mktime (lt) == now;
82
return (mktime_test1 (now)
83
&& mktime_test1 ((time_t) (time_t_max - now))
84
&& mktime_test1 ((time_t) (time_t_min + now)));
90
/* Based on code from Ariel Faigon. */
100
return tm.tm_mon == 2 && tm.tm_mday == 31;
109
tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
111
if (now != (time_t) -1)
113
struct tm *lt = localtime (&now);
115
&& lt->tm_year == tm.tm_year
116
&& lt->tm_mon == tm.tm_mon
117
&& lt->tm_mday == tm.tm_mday
118
&& lt->tm_hour == tm.tm_hour
119
&& lt->tm_min == tm.tm_min
120
&& lt->tm_sec == tm.tm_sec
121
&& lt->tm_yday == tm.tm_yday
122
&& lt->tm_wday == tm.tm_wday
123
&& ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
124
== (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
133
/* The correct answer for 2050-02-01 00:00:00 in Pacific time,
134
ignoring leap seconds. */
135
unsigned long int answer = 2527315200UL;
139
tm.tm_year = 2050 - 1900;
142
tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
145
/* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
146
instead of "TZ=America/Vancouver" in order to detect the bug even
147
on systems that don't support the Olson extension, or don't have the
148
full zoneinfo tables installed. */
149
putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
153
/* Check that the result is either a failure, or close enough
154
to the correct answer that we can assume the discrepancy is
155
due to leap seconds. */
156
return (t == (time_t) -1
157
|| (0 < t && answer - 120 <= t && t <= answer + 120));
166
/* This test makes some buggy mktime implementations loop.
167
Give up after 60 seconds; a mktime slower than that
168
isn't worth using anyway. */
173
t = (time_t_max << 1) + 1;
178
time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max;
180
delta = time_t_max / 997; /* a suitable prime number */
181
for (i = 0; i < N_STRINGS; i++)
184
putenv (tz_strings[i]);
186
for (t = 0; t <= time_t_max - delta; t += delta)
187
if (! mktime_test (t))
189
if (! (mktime_test ((time_t) 1)
190
&& mktime_test ((time_t) (60 * 60))
191
&& mktime_test ((time_t) (60 * 60 * 24))))
194
for (j = 1; ; j <<= 1)
195
if (! bigtime_test (j))
197
else if (INT_MAX / 2 < j)
199
if (! bigtime_test (INT_MAX))
202
return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());
204
[ac_cv_func_working_mktime=yes],
205
[ac_cv_func_working_mktime=no],
206
[ac_cv_func_working_mktime=no])])
207
if test $ac_cv_func_working_mktime = no; then
212
AC_DEFUN([gl_FUNC_MKTIME],
214
AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
216
dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]).
217
if test $ac_cv_func_working_mktime = no; then
223
# Prerequisites of lib/mktime.c.
224
AC_DEFUN([gl_PREREQ_MKTIME],
226
AC_REQUIRE([AC_C_INLINE])