4 dnl Check for a working mktime.
5 dnl This is a preview of what should appear in the next public autoconf release.
7 dnl Override any existing definition.
8 undefine([AC_FUNC_MKTIME])
10 AC_DEFUN(AC_FUNC_MKTIME,
11 [AC_REQUIRE([AC_HEADER_TIME])dnl
12 AC_CHECK_HEADERS(sys/time.h unistd.h)
14 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
16 changequote(<<, >>)dnl
17 <</* Test program from Paul Eggert (eggert@twinsun.com)
18 and Tony Leneis (tony@plaza.ds.adp.com). */
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
35 # define alarm(X) /* empty */
38 /* Work around redefinition to rpl_putenv by other config tests. */
41 static time_t time_t_max;
43 /* Values we'll use to set the TZ environment variable. */
44 static const char *const tz_strings[] = {
45 (const 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 /* Fail 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 if (mktime (&tm) == (time_t)-1)
80 if ((lt = localtime (&now)) && mktime (lt) != now)
82 now = time_t_max - now;
83 if ((lt = localtime (&now)) && mktime (lt) != now)
90 /* Based on code from Ariel Faigon. */
100 if (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))))
136 /* This test makes some buggy mktime implementations loop.
137 Give up after 60 seconds; a mktime slower than that
138 isn't worth using anyway. */
141 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
144 delta = time_t_max / 997; /* a suitable prime number */
145 for (i = 0; i < N_STRINGS; i++)
148 putenv (tz_strings[i]);
150 for (t = 0; t <= time_t_max - delta; t += delta)
152 mktime_test ((time_t) 60 * 60);
153 mktime_test ((time_t) 60 * 60 * 24);
155 for (j = 1; 0 < j; j *= 2)
157 bigtime_test (j - 1);
160 spring_forward_gap ();
165 ac_cv_func_working_mktime=yes, ac_cv_func_working_mktime=no,
166 ac_cv_func_working_mktime=no)])
167 if test $ac_cv_func_working_mktime = no; then
168 LIBOBJS="$LIBOBJS mktime.${ac_objext}"