4 dnl Check for a working mktime.
5 dnl This is a preview of what should appear in the next public autoconf release.
7 AC_DEFUN(AC_FUNC_MKTIME,
8 [AC_REQUIRE([AC_HEADER_TIME])dnl
9 AC_CHECK_HEADERS(sys/time.h unistd.h)
11 AC_CACHE_CHECK([for working mktime], ac_cv_func_working_mktime,
13 changequote(<<, >>)dnl
14 <</* Test program from Paul Eggert (eggert@twinsun.com)
15 and Tony Leneis (tony@plaza.ds.adp.com). */
16 #if TIME_WITH_SYS_TIME
17 # include <sys/time.h>
21 # include <sys/time.h>
32 # define alarm(X) /* empty */
35 /* Work around redefinition to rpl_putenv by other config tests. */
38 static time_t time_t_max;
40 /* Values we'll use to set the TZ environment variable. */
41 static const char *const tz_strings[] = {
42 (const char *) 0, "TZ=GMT0", "TZ=JST-9",
43 "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
45 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
47 /* Fail if mktime fails to convert a date in the spring-forward gap.
48 Based on a problem report from Andreas Jaeger. */
52 /* glibc (up to about 1998-10-07) failed this test) */
55 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
56 instead of "TZ=America/Vancouver" in order to detect the bug even
57 on systems that don't support the Olson extension, or don't have the
58 full zoneinfo tables installed. */
59 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
68 if (mktime (&tm) == (time_t)-1)
77 if ((lt = localtime (&now)) && mktime (lt) != now)
79 now = time_t_max - now;
80 if ((lt = localtime (&now)) && mktime (lt) != now)
87 /* Based on code from Ariel Faigon. */
97 if (tm.tm_mon != 2 || tm.tm_mday != 31)
107 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
109 if (now != (time_t) -1)
111 struct tm *lt = localtime (&now);
113 && lt->tm_year == tm.tm_year
114 && lt->tm_mon == tm.tm_mon
115 && lt->tm_mday == tm.tm_mday
116 && lt->tm_hour == tm.tm_hour
117 && lt->tm_min == tm.tm_min
118 && lt->tm_sec == tm.tm_sec
119 && lt->tm_yday == tm.tm_yday
120 && lt->tm_wday == tm.tm_wday
121 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
122 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
133 /* This test makes some buggy mktime implementations loop.
134 Give up after 60 seconds; a mktime slower than that
135 isn't worth using anyway. */
138 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
141 delta = time_t_max / 997; /* a suitable prime number */
142 for (i = 0; i < N_STRINGS; i++)
145 putenv (tz_strings[i]);
147 for (t = 0; t <= time_t_max - delta; t += delta)
149 mktime_test ((time_t) 60 * 60);
150 mktime_test ((time_t) 60 * 60 * 24);
152 for (j = 1; 0 < j; j *= 2)
154 bigtime_test (j - 1);
157 spring_forward_gap ();
162 ac_cv_func_working_mktime=yes, ac_cv_func_working_mktime=no,
163 ac_cv_func_working_mktime=no)])
164 if test $ac_cv_func_working_mktime = no; then
165 LIBOBJS="$LIBOBJS mktime.${ac_objext}"