2 dnl FIXME: when this goes back into automake, reset this to a small number
5 dnl FIXME: this should migrate into libit.
7 dnl FIXME: when this goes back into automake, remove all jm_ prefixes
9 AC_DEFUN(jm_AM_FUNC_MKTIME,
10 [AC_REQUIRE([AC_HEADER_TIME])dnl
11 AC_CHECK_HEADERS(sys/time.h unistd.h)
13 AC_CACHE_CHECK([for working mktime], jm_am_cv_func_working_mktime,
15 changequote(<<, >>)dnl
16 <</* Test program from Paul Eggert (eggert@twinsun.com)
17 and Tony Leneis (tony@plaza.ds.adp.com). */
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
23 # include <sys/time.h>
34 # define alarm(X) /* empty */
37 /* Work around redefinition to rpl_putenv by other config tests. */
40 static time_t time_t_max;
42 /* Values we'll use to set the TZ environment variable. */
43 static const char *const tz_strings[] = {
44 (const char *) 0, "GMT0", "JST-9",
45 "EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
47 #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
54 if ((lt = localtime (&now)) && mktime (lt) != now)
56 now = time_t_max - now;
57 if ((lt = localtime (&now)) && mktime (lt) != now)
64 /* Based on code from Ariel Faigon. */
74 if (tm.tm_mon != 2 || tm.tm_mday != 31)
84 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
85 /* This test makes some buggy mktime implementations loop.
86 Give up after 10 seconds. */
90 if (now != (time_t) -1)
92 struct tm *lt = localtime (&now);
94 && lt->tm_year == tm.tm_year
95 && lt->tm_mon == tm.tm_mon
96 && lt->tm_mday == tm.tm_mday
97 && lt->tm_hour == tm.tm_hour
98 && lt->tm_min == tm.tm_min
99 && lt->tm_sec == tm.tm_sec
100 && lt->tm_yday == tm.tm_yday
101 && lt->tm_wday == tm.tm_wday
102 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
103 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
114 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
117 delta = time_t_max / 997; /* a suitable prime number */
118 for (i = 0; i < N_STRINGS; i++)
121 putenv (tz_strings[i]);
123 for (t = 0; t <= time_t_max - delta; t += delta)
125 mktime_test ((time_t) 60 * 60);
126 mktime_test ((time_t) 60 * 60 * 24);
128 for (j = 1; 0 < j; j *= 2)
130 bigtime_test (j - 1);
137 jm_am_cv_func_working_mktime=yes, jm_am_cv_func_working_mktime=no,
138 dnl When crosscompiling, assume mktime is missing or broken.
139 jm_am_cv_func_working_mktime=no)
141 if test $jm_am_cv_func_working_mktime = no; then
142 LIBOBJS="$LIBOBJS mktime.o"