1 | #serial 4
|
---|
2 |
|
---|
3 | dnl From Jim Meyering.
|
---|
4 | dnl FIXME: this should migrate into libit.
|
---|
5 |
|
---|
6 | AC_DEFUN([AM_FUNC_MKTIME],
|
---|
7 | [AC_REQUIRE([AC_HEADER_TIME])dnl
|
---|
8 | AC_CHECK_HEADERS(sys/time.h unistd.h)
|
---|
9 | AC_CHECK_FUNCS(alarm)
|
---|
10 | AC_CACHE_CHECK([for working mktime], am_cv_func_working_mktime,
|
---|
11 | [AC_TRY_RUN(
|
---|
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>
|
---|
17 | # include <time.h>
|
---|
18 | #else
|
---|
19 | # if HAVE_SYS_TIME_H
|
---|
20 | # include <sys/time.h>
|
---|
21 | # else
|
---|
22 | # include <time.h>
|
---|
23 | # endif
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #if HAVE_UNISTD_H
|
---|
27 | # include <unistd.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | #if !HAVE_ALARM
|
---|
31 | # define alarm(X) /* empty */
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Work around redefinition to rpl_putenv by other config tests. */
|
---|
35 | #undef putenv
|
---|
36 |
|
---|
37 | static time_t time_t_max;
|
---|
38 |
|
---|
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"
|
---|
43 | };
|
---|
44 | #define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
|
---|
45 |
|
---|
46 | /* Fail if mktime fails to convert a date in the spring-forward gap.
|
---|
47 | Based on a problem report from Andreas Jaeger. */
|
---|
48 | static void
|
---|
49 | spring_forward_gap ()
|
---|
50 | {
|
---|
51 | /* glibc (up to about 1998-10-07) failed this test) */
|
---|
52 | struct tm tm;
|
---|
53 |
|
---|
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");
|
---|
59 |
|
---|
60 | tm.tm_year = 98;
|
---|
61 | tm.tm_mon = 3;
|
---|
62 | tm.tm_mday = 5;
|
---|
63 | tm.tm_hour = 2;
|
---|
64 | tm.tm_min = 0;
|
---|
65 | tm.tm_sec = 0;
|
---|
66 | tm.tm_isdst = -1;
|
---|
67 | if (mktime (&tm) == (time_t)-1)
|
---|
68 | exit (1);
|
---|
69 | }
|
---|
70 |
|
---|
71 | static void
|
---|
72 | mktime_test (now)
|
---|
73 | time_t now;
|
---|
74 | {
|
---|
75 | struct tm *lt;
|
---|
76 | if ((lt = localtime (&now)) && mktime (lt) != now)
|
---|
77 | exit (1);
|
---|
78 | now = time_t_max - now;
|
---|
79 | if ((lt = localtime (&now)) && mktime (lt) != now)
|
---|
80 | exit (1);
|
---|
81 | }
|
---|
82 |
|
---|
83 | static void
|
---|
84 | irix_6_4_bug ()
|
---|
85 | {
|
---|
86 | /* Based on code from Ariel Faigon. */
|
---|
87 | struct tm tm;
|
---|
88 | tm.tm_year = 96;
|
---|
89 | tm.tm_mon = 3;
|
---|
90 | tm.tm_mday = 0;
|
---|
91 | tm.tm_hour = 0;
|
---|
92 | tm.tm_min = 0;
|
---|
93 | tm.tm_sec = 0;
|
---|
94 | tm.tm_isdst = -1;
|
---|
95 | mktime (&tm);
|
---|
96 | if (tm.tm_mon != 2 || tm.tm_mday != 31)
|
---|
97 | exit (1);
|
---|
98 | }
|
---|
99 |
|
---|
100 | static void
|
---|
101 | bigtime_test (j)
|
---|
102 | int j;
|
---|
103 | {
|
---|
104 | struct tm tm;
|
---|
105 | time_t now;
|
---|
106 | tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
|
---|
107 | /* This test makes some buggy mktime implementations loop.
|
---|
108 | Give up after 10 seconds. */
|
---|
109 | alarm (10);
|
---|
110 | now = mktime (&tm);
|
---|
111 | alarm (0);
|
---|
112 | if (now != (time_t) -1)
|
---|
113 | {
|
---|
114 | struct tm *lt = localtime (&now);
|
---|
115 | if (! (lt
|
---|
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))))
|
---|
126 | exit (1);
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | int
|
---|
131 | main ()
|
---|
132 | {
|
---|
133 | time_t t, delta;
|
---|
134 | int i, j;
|
---|
135 |
|
---|
136 | for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
|
---|
137 | continue;
|
---|
138 | time_t_max--;
|
---|
139 | delta = time_t_max / 997; /* a suitable prime number */
|
---|
140 | for (i = 0; i < N_STRINGS; i++)
|
---|
141 | {
|
---|
142 | if (tz_strings[i])
|
---|
143 | putenv (tz_strings[i]);
|
---|
144 |
|
---|
145 | for (t = 0; t <= time_t_max - delta; t += delta)
|
---|
146 | mktime_test (t);
|
---|
147 | mktime_test ((time_t) 60 * 60);
|
---|
148 | mktime_test ((time_t) 60 * 60 * 24);
|
---|
149 |
|
---|
150 | for (j = 1; 0 < j; j *= 2)
|
---|
151 | bigtime_test (j);
|
---|
152 | bigtime_test (j - 1);
|
---|
153 | }
|
---|
154 | irix_6_4_bug ();
|
---|
155 | spring_forward_gap ();
|
---|
156 | exit (0);
|
---|
157 | }
|
---|
158 | >>,
|
---|
159 | changequote([, ])dnl
|
---|
160 | am_cv_func_working_mktime=yes, am_cv_func_working_mktime=no,
|
---|
161 | dnl When crosscompiling, assume mktime is missing or broken.
|
---|
162 | am_cv_func_working_mktime=no)
|
---|
163 | ])
|
---|
164 | if test $am_cv_func_working_mktime = no; then
|
---|
165 | LIBOBJS="$LIBOBJS mktime.o"
|
---|
166 | fi
|
---|
167 | ])
|
---|