summaryrefslogtreecommitdiffstats
path: root/gl/m4/mktime.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/mktime.m4')
-rw-r--r--gl/m4/mktime.m4115
1 files changed, 80 insertions, 35 deletions
diff --git a/gl/m4/mktime.m4 b/gl/m4/mktime.m4
index faefb770..721189af 100644
--- a/gl/m4/mktime.m4
+++ b/gl/m4/mktime.m4
@@ -1,5 +1,5 @@
1# serial 25 1# serial 36
2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2013 Free Software Foundation, 2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2021 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl 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
8dnl From Jim Meyering. 8dnl From Jim Meyering.
9 9
10AC_DEFUN([gl_FUNC_MKTIME], 10AC_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
24dnl Test whether mktime works. Set gl_cv_func_working_mktime.
25AC_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
44static time_t time_t_max; 63static time_t time_t_max;
45static time_t time_t_min; 64static time_t time_t_min;
@@ -169,7 +188,6 @@ main ()
169 time_t t, delta; 188 time_t t, delta;
170 int i, j; 189 int i, j;
171 int time_t_signed_magnitude = (time_t) ~ (time_t) 0 < (time_t) -1; 190 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 191
174#if HAVE_DECL_ALARM 192#if HAVE_DECL_ALARM
175 /* This test makes some buggy mktime implementations loop. 193 /* This test makes some buggy mktime implementations loop.
@@ -179,11 +197,11 @@ main ()
179 alarm (60); 197 alarm (60);
180#endif 198#endif
181 199
182 time_t_max = (! time_t_signed 200 time_t_max = (! TIME_T_IS_SIGNED
183 ? (time_t) -1 201 ? (time_t) -1
184 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1) 202 : ((((time_t) 1 << (sizeof (time_t) * CHAR_BIT - 2)) - 1)
185 * 2 + 1)); 203 * 2 + 1));
186 time_t_min = (! time_t_signed 204 time_t_min = (! TIME_T_IS_SIGNED
187 ? (time_t) 0 205 ? (time_t) 0
188 : time_t_signed_magnitude 206 : time_t_signed_magnitude
189 ? ~ (time_t) 0 207 ? ~ (time_t) 0
@@ -222,31 +240,58 @@ main ()
222 result |= 64; 240 result |= 64;
223 return result; 241 return result;
224}]])], 242}]])],
225 [gl_cv_func_working_mktime=yes], 243 [gl_cv_func_working_mktime=yes],
226 [gl_cv_func_working_mktime=no], 244 [gl_cv_func_working_mktime=no],
227 [gl_cv_func_working_mktime=no]) 245 [case "$host_os" in
246 # Guess no on native Windows.
247 mingw*) gl_cv_func_working_mktime="guessing no" ;;
248 *) gl_cv_func_working_mktime="$gl_cross_guess_normal" ;;
249 esac
250 ])
251 fi
228 ]) 252 ])
253])
254
255dnl Main macro of module 'mktime'.
256AC_DEFUN([gl_FUNC_MKTIME],
257[
258 AC_REQUIRE([gl_TIME_H_DEFAULTS])
259 AC_REQUIRE([AC_CANONICAL_HOST])
260 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
229 261
230 if test $gl_cv_func_working_mktime = no; then 262 REPLACE_MKTIME=0
263 if test "$gl_cv_func_working_mktime" != yes; then
231 REPLACE_MKTIME=1 264 REPLACE_MKTIME=1
232 else 265 AC_DEFINE([NEED_MKTIME_WORKING], [1],
233 REPLACE_MKTIME=0 266 [Define if the compilation of mktime.c should define 'mktime'
267 with the algorithmic workarounds.])
234 fi 268 fi
269 case "$host_os" in
270 mingw*)
271 REPLACE_MKTIME=1
272 AC_DEFINE([NEED_MKTIME_WINDOWS], [1],
273 [Define if the compilation of mktime.c should define 'mktime'
274 with the native Windows TZ workaround.])
275 ;;
276 esac
235]) 277])
236 278
279dnl Main macro of module 'mktime-internal'.
237AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [ 280AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [
238 AC_REQUIRE([gl_FUNC_MKTIME]) 281 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
239 if test $REPLACE_MKTIME = 0; then 282
240 dnl BeOS has __mktime_internal in libc, but other platforms don't. 283 WANT_MKTIME_INTERNAL=0
241 AC_CHECK_FUNC([__mktime_internal], 284 dnl BeOS has __mktime_internal in libc, but other platforms don't.
242 [AC_DEFINE([mktime_internal], [__mktime_internal], 285 AC_CHECK_FUNC([__mktime_internal],
243 [Define to the real name of the mktime_internal function.]) 286 [AC_DEFINE([mktime_internal], [__mktime_internal],
244 ], 287 [Define to the real name of the mktime_internal function.])
245 [dnl mktime works but it doesn't export __mktime_internal, 288 ],
246 dnl so we need to substitute our own mktime implementation. 289 [dnl mktime works but it doesn't export __mktime_internal,
247 REPLACE_MKTIME=1 290 dnl so we need to substitute our own mktime implementation.
248 ]) 291 WANT_MKTIME_INTERNAL=1
249 fi 292 AC_DEFINE([NEED_MKTIME_INTERNAL], [1],
293 [Define if the compilation of mktime.c should define 'mktime_internal'.])
294 ])
250]) 295])
251 296
252# Prerequisites of lib/mktime.c. 297# Prerequisites of lib/mktime.c.