3 dnl Just like mktime.m4 from automake-1.3b, but with an additional test.
4 dnl Renamed to have jm_ prefix and to use jm_ prefix on cache variable names.
6 AC_DEFUN(jm_AM_FUNC_MKTIME,
7 [AC_REQUIRE([AC_HEADER_TIME])dnl
8 AC_CHECK_HEADERS(sys/time.h unistd.h)
10 AC_CACHE_CHECK([for working mktime], jm_am_cv_func_working_mktime,
12 changequote(<<, >>)dnl
13 <</* Test program from Paul Eggert (eggert@twinsun.com)
14 and Tony Leneis (tony@plaza.ds.adp.com). */
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
20 # include <sys/time.h>
31 # define alarm(X) /* empty */
34 /* Work around redefinition to rpl_putenv by other config tests. */
37 static time_t time_t_max;
39 /* Values we'll use to set the TZ environment variable. */
40 static const char *const tz_strings[] = {
41 (const 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 /* Fail 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");
66 if (mktime (&tm) == (time_t)-1)
75 if ((lt = localtime (&now)) && mktime (lt) != now)
77 now = time_t_max - now;
78 if ((lt = localtime (&now)) && mktime (lt) != now)
85 /* Based on code from Ariel Faigon. */
95 if (tm.tm_mon != 2 || tm.tm_mday != 31)
105 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
106 /* This test makes some buggy mktime implementations loop.
107 Give up after 10 seconds. */
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))))
135 spring_forward_gap ();
136 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
139 delta = time_t_max / 997; /* a suitable prime number */
140 for (i = 0; i < N_STRINGS; i++)
143 putenv (tz_strings[i]);
145 for (t = 0; t <= time_t_max - delta; t += delta)
147 mktime_test ((time_t) 60 * 60);
148 mktime_test ((time_t) 60 * 60 * 24);
150 for (j = 1; 0 < j; j *= 2)
152 bigtime_test (j - 1);
159 jm_am_cv_func_working_mktime=yes, jm_am_cv_func_working_mktime=no,
160 dnl When crosscompiling, assume mktime is missing or broken.
161 jm_am_cv_func_working_mktime=no)
163 if test $jm_am_cv_func_working_mktime = no; then
164 LIBOBJS="$LIBOBJS mktime.o"