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 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, "GMT0", "JST-9",
42 "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]))
51 if ((lt = localtime (&now)) && mktime (lt) != now)
53 now = time_t_max - now;
54 if ((lt = localtime (&now)) && mktime (lt) != now)
61 /* Based on code from Ariel Faigon. */
71 if (tm.tm_mon != 2 || tm.tm_mday != 31)
81 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
82 /* This test makes some buggy mktime implementations loop.
83 Give up after 10 seconds. */
87 if (now != (time_t) -1)
89 struct tm *lt = localtime (&now);
91 && lt->tm_year == tm.tm_year
92 && lt->tm_mon == tm.tm_mon
93 && lt->tm_mday == tm.tm_mday
94 && lt->tm_hour == tm.tm_hour
95 && lt->tm_min == tm.tm_min
96 && lt->tm_sec == tm.tm_sec
97 && lt->tm_yday == tm.tm_yday
98 && lt->tm_wday == tm.tm_wday
99 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
100 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
111 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
114 delta = time_t_max / 997; /* a suitable prime number */
115 for (i = 0; i < N_STRINGS; i++)
118 putenv (tz_strings[i]);
120 for (t = 0; t <= time_t_max - delta; t += delta)
122 mktime_test ((time_t) 60 * 60);
123 mktime_test ((time_t) 60 * 60 * 24);
125 for (j = 1; 0 < j; j *= 2)
127 bigtime_test (j - 1);
134 jm_am_cv_func_working_mktime=yes, jm_am_cv_func_working_mktime=no,
135 dnl When crosscompiling, assume mktime is missing or broken.
136 jm_am_cv_func_working_mktime=no)
138 if test $jm_am_cv_func_working_mktime = no; then
139 LIBOBJS="$LIBOBJS mktime.o"