diff options
Diffstat (limited to 'gl/m4/mktime.m4')
-rw-r--r-- | gl/m4/mktime.m4 | 142 |
1 files changed, 104 insertions, 38 deletions
diff --git a/gl/m4/mktime.m4 b/gl/m4/mktime.m4 index faefb77..e9d31f3 100644 --- a/gl/m4/mktime.m4 +++ b/gl/m4/mktime.m4 | |||
@@ -1,5 +1,5 @@ | |||
1 | # serial 25 | 1 | # serial 37 |
2 | dnl Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, | 2 | dnl Copyright (C) 2002-2003, 2005-2007, 2009-2023 Free Software Foundation, |
3 | dnl Inc. | 3 | dnl Inc. |
4 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
5 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
@@ -7,24 +7,40 @@ dnl with or without modifications, as long as this notice is preserved. | |||
7 | 7 | ||
8 | dnl From Jim Meyering. | 8 | dnl From Jim Meyering. |
9 | 9 | ||
10 | AC_DEFUN([gl_FUNC_MKTIME], | 10 | AC_DEFUN([gl_TIME_T_IS_SIGNED], |
11 | [ | ||
12 | AC_CACHE_CHECK([whether time_t is signed], | ||
13 | [gl_cv_time_t_is_signed], | ||
14 | [AC_COMPILE_IFELSE( | ||
15 | [AC_LANG_PROGRAM([[#include <time.h> | ||
16 | char time_t_signed[(time_t) -1 < 0 ? 1 : -1];]])], | ||
17 | [gl_cv_time_t_is_signed=yes], | ||
18 | [gl_cv_time_t_is_signed=no])]) | ||
19 | if test $gl_cv_time_t_is_signed = yes; then | ||
20 | AC_DEFINE([TIME_T_IS_SIGNED], [1], [Define to 1 if time_t is signed.]) | ||
21 | fi | ||
22 | ]) | ||
23 | |||
24 | dnl Test whether mktime works. Set gl_cv_func_working_mktime. | ||
25 | AC_DEFUN([gl_FUNC_MKTIME_WORKS], | ||
11 | [ | 26 | [ |
12 | AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) | 27 | AC_REQUIRE([gl_TIME_T_IS_SIGNED]) |
28 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
13 | 29 | ||
14 | dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained | 30 | dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained |
15 | dnl in Autoconf and because it invokes AC_LIBOBJ. | 31 | dnl in Autoconf and because it invokes AC_LIBOBJ. |
16 | AC_CHECK_HEADERS_ONCE([unistd.h]) | 32 | AC_CHECK_HEADERS_ONCE([unistd.h]) |
17 | AC_CHECK_DECLS_ONCE([alarm]) | 33 | AC_CHECK_DECLS_ONCE([alarm]) |
18 | AC_REQUIRE([gl_MULTIARCH]) | 34 | AC_REQUIRE([gl_MULTIARCH]) |
19 | if test $APPLE_UNIVERSAL_BUILD = 1; then | ||
20 | # A universal build on Apple Mac OS X platforms. | ||
21 | # The test result would be 'yes' in 32-bit mode and 'no' in 64-bit mode. | ||
22 | # But we need a configuration result that is valid in both modes. | ||
23 | gl_cv_func_working_mktime=no | ||
24 | fi | ||
25 | AC_CACHE_CHECK([for working mktime], [gl_cv_func_working_mktime], | 35 | AC_CACHE_CHECK([for working mktime], [gl_cv_func_working_mktime], |
26 | [AC_RUN_IFELSE( | 36 | [if test $APPLE_UNIVERSAL_BUILD = 1; then |
27 | [AC_LANG_SOURCE( | 37 | # A universal build on Apple Mac OS X platforms. |
38 | # The test result would be 'yes' in 32-bit mode and 'no' in 64-bit mode. | ||
39 | # But we need a configuration result that is valid in both modes. | ||
40 | gl_cv_func_working_mktime="guessing no" | ||
41 | else | ||
42 | AC_RUN_IFELSE( | ||
43 | [AC_LANG_SOURCE( | ||
28 | [[/* Test program from Paul Eggert and Tony Leneis. */ | 44 | [[/* Test program from Paul Eggert and Tony Leneis. */ |
29 | #include <limits.h> | 45 | #include <limits.h> |
30 | #include <stdlib.h> | 46 | #include <stdlib.h> |
@@ -38,8 +54,11 @@ AC_DEFUN([gl_FUNC_MKTIME], | |||
38 | # include <signal.h> | 54 | # include <signal.h> |
39 | #endif | 55 | #endif |
40 | 56 | ||
41 | /* Work around redefinition to rpl_putenv by other config tests. */ | 57 | ]GL_MDA_DEFINES[ |
42 | #undef putenv | 58 | |
59 | #ifndef TIME_T_IS_SIGNED | ||
60 | # define TIME_T_IS_SIGNED 0 | ||
61 | #endif | ||
43 | 62 | ||
44 | static time_t time_t_max; | 63 | static time_t time_t_max; |
45 | static time_t time_t_min; | 64 | static time_t time_t_min; |
@@ -63,7 +82,8 @@ spring_forward_gap () | |||
63 | instead of "TZ=America/Vancouver" in order to detect the bug even | 82 | instead of "TZ=America/Vancouver" in order to detect the bug even |
64 | on systems that don't support the Olson extension, or don't have the | 83 | on systems that don't support the Olson extension, or don't have the |
65 | full zoneinfo tables installed. */ | 84 | full zoneinfo tables installed. */ |
66 | putenv ("TZ=PST8PDT,M4.1.0,M10.5.0"); | 85 | if (putenv ("TZ=PST8PDT,M4.1.0,M10.5.0") != 0) |
86 | return -1; | ||
67 | 87 | ||
68 | tm.tm_year = 98; | 88 | tm.tm_year = 98; |
69 | tm.tm_mon = 3; | 89 | tm.tm_mon = 3; |
@@ -151,7 +171,8 @@ year_2050_test () | |||
151 | instead of "TZ=America/Vancouver" in order to detect the bug even | 171 | instead of "TZ=America/Vancouver" in order to detect the bug even |
152 | on systems that don't support the Olson extension, or don't have the | 172 | on systems that don't support the Olson extension, or don't have the |
153 | full zoneinfo tables installed. */ | 173 | full zoneinfo tables installed. */ |
154 | putenv ("TZ=PST8PDT,M4.1.0,M10.5.0"); | 174 | if (putenv ("TZ=PST8PDT,M4.1.0,M10.5.0") != 0) |
175 | return -1; | ||
155 | 176 | ||
156 | t = mktime (&tm); | 177 | t = mktime (&tm); |
157 | 178 | ||
@@ -162,6 +183,25 @@ year_2050_test () | |||
162 | || (0 < t && answer - 120 <= t && t <= answer + 120)); | 183 | || (0 < t && answer - 120 <= t && t <= answer + 120)); |
163 | } | 184 | } |
164 | 185 | ||
186 | static int | ||
187 | indiana_test () | ||
188 | { | ||
189 | if (putenv ("TZ=America/Indiana/Indianapolis") != 0) | ||
190 | return -1; | ||
191 | struct tm tm; | ||
192 | tm.tm_year = 1986 - 1900; tm.tm_mon = 4 - 1; tm.tm_mday = 28; | ||
193 | tm.tm_hour = 16; tm.tm_min = 24; tm.tm_sec = 50; tm.tm_isdst = 0; | ||
194 | time_t std = mktime (&tm); | ||
195 | if (! (std == 515107490 || std == 515107503)) | ||
196 | return 1; | ||
197 | |||
198 | /* This platform supports TZDB, either without or with leap seconds. | ||
199 | Return true if GNU Bug#48085 is absent. */ | ||
200 | tm.tm_isdst = 1; | ||
201 | time_t dst = mktime (&tm); | ||
202 | return std - dst == 60 * 60; | ||
203 | } | ||
204 | |||
165 | int | 205 | int |
166 | main () | 206 | main () |
167 | { | 207 | { |
@@ -169,7 +209,6 @@ main () | |||
169 | time_t t, delta; | 209 | time_t t, delta; |
170 | int i, j; | 210 | int i, j; |
171 | int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1; | 211 | int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1; |
172 | int time_t_signed = ! ((time_t) 0 < (time_t) -1); | ||
173 | 212 | ||
174 | #if HAVE_DECL_ALARM | 213 | #if HAVE_DECL_ALARM |
175 | /* This test makes some buggy mktime implementations loop. | 214 | /* This test makes some buggy mktime implementations loop. |
@@ -179,11 +218,11 @@ main () | |||
179 | alarm (60); | 218 | alarm (60); |
180 | #endif | 219 | #endif |
181 | 220 | ||
182 | time_t_max = (! time_t_signed | 221 | time_t_max = (! TIME_T_IS_SIGNED |
183 | ? (time_t) -1 | 222 | ? (time_t) -1 |
184 | : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1) | 223 | : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1) |
185 | * 2 + 1)); | 224 | * 2 + 1)); |
186 | time_t_min = (! time_t_signed | 225 | time_t_min = (! TIME_T_IS_SIGNED |
187 | ? (time_t) 0 | 226 | ? (time_t) 0 |
188 | : time_t_signed_magnitude | 227 | : time_t_signed_magnitude |
189 | ? ~ (time_t) 0 | 228 | ? ~ (time_t) 0 |
@@ -218,35 +257,62 @@ main () | |||
218 | result |= 16; | 257 | result |= 16; |
219 | if (! spring_forward_gap ()) | 258 | if (! spring_forward_gap ()) |
220 | result |= 32; | 259 | result |= 32; |
221 | if (! year_2050_test ()) | 260 | if (! year_2050_test () || ! indiana_test ()) |
222 | result |= 64; | 261 | result |= 64; |
223 | return result; | 262 | return result; |
224 | }]])], | 263 | }]])], |
225 | [gl_cv_func_working_mktime=yes], | 264 | [gl_cv_func_working_mktime=yes], |
226 | [gl_cv_func_working_mktime=no], | 265 | [gl_cv_func_working_mktime=no], |
227 | [gl_cv_func_working_mktime=no]) | 266 | [case "$host_os" in |
267 | # Guess no on native Windows. | ||
268 | mingw*) gl_cv_func_working_mktime="guessing no" ;; | ||
269 | *) gl_cv_func_working_mktime="$gl_cross_guess_normal" ;; | ||
270 | esac | ||
271 | ]) | ||
272 | fi | ||
228 | ]) | 273 | ]) |
274 | ]) | ||
275 | |||
276 | dnl Main macro of module 'mktime'. | ||
277 | AC_DEFUN([gl_FUNC_MKTIME], | ||
278 | [ | ||
279 | AC_REQUIRE([gl_TIME_H_DEFAULTS]) | ||
280 | AC_REQUIRE([AC_CANONICAL_HOST]) | ||
281 | AC_REQUIRE([gl_FUNC_MKTIME_WORKS]) | ||
229 | 282 | ||
230 | if test $gl_cv_func_working_mktime = no; then | 283 | REPLACE_MKTIME=0 |
284 | if test "$gl_cv_func_working_mktime" != yes; then | ||
231 | REPLACE_MKTIME=1 | 285 | REPLACE_MKTIME=1 |
232 | else | 286 | AC_DEFINE([NEED_MKTIME_WORKING], [1], |
233 | REPLACE_MKTIME=0 | 287 | [Define if the compilation of mktime.c should define 'mktime' |
288 | with the algorithmic workarounds.]) | ||
234 | fi | 289 | fi |
290 | case "$host_os" in | ||
291 | mingw*) | ||
292 | REPLACE_MKTIME=1 | ||
293 | AC_DEFINE([NEED_MKTIME_WINDOWS], [1], | ||
294 | [Define if the compilation of mktime.c should define 'mktime' | ||
295 | with the native Windows TZ workaround.]) | ||
296 | ;; | ||
297 | esac | ||
235 | ]) | 298 | ]) |
236 | 299 | ||
300 | dnl Main macro of module 'mktime-internal'. | ||
237 | AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [ | 301 | AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [ |
238 | AC_REQUIRE([gl_FUNC_MKTIME]) | 302 | AC_REQUIRE([gl_FUNC_MKTIME_WORKS]) |
239 | if test $REPLACE_MKTIME = 0; then | 303 | |
240 | dnl BeOS has __mktime_internal in libc, but other platforms don't. | 304 | WANT_MKTIME_INTERNAL=0 |
241 | AC_CHECK_FUNC([__mktime_internal], | 305 | dnl BeOS has __mktime_internal in libc, but other platforms don't. |
242 | [AC_DEFINE([mktime_internal], [__mktime_internal], | 306 | AC_CHECK_FUNC([__mktime_internal], |
243 | [Define to the real name of the mktime_internal function.]) | 307 | [AC_DEFINE([mktime_internal], [__mktime_internal], |
244 | ], | 308 | [Define to the real name of the mktime_internal function.]) |
245 | [dnl mktime works but it doesn't export __mktime_internal, | 309 | ], |
246 | dnl so we need to substitute our own mktime implementation. | 310 | [dnl mktime works but it doesn't export __mktime_internal, |
247 | REPLACE_MKTIME=1 | 311 | dnl so we need to substitute our own mktime implementation. |
248 | ]) | 312 | WANT_MKTIME_INTERNAL=1 |
249 | fi | 313 | AC_DEFINE([NEED_MKTIME_INTERNAL], [1], |
314 | [Define if the compilation of mktime.c should define 'mktime_internal'.]) | ||
315 | ]) | ||
250 | ]) | 316 | ]) |
251 | 317 | ||
252 | # Prerequisites of lib/mktime.c. | 318 | # Prerequisites of lib/mktime.c. |