1# year2038.m4 serial 7 2dnl Copyright (C) 2017-2022 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl Attempt to ensure that 'time_t' can go past the year 2038 and that 8dnl the functions 'time', 'stat', etc. work with post-2038 timestamps. 9 10AC_DEFUN([gl_YEAR2038_EARLY], 11[ 12 AC_REQUIRE([AC_CANONICAL_HOST]) 13 case "$host_os" in 14 mingw*) 15 AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1], 16 [For 64-bit time_t on 32-bit mingw.]) 17 ;; 18 esac 19]) 20 21# gl_YEAR2038_TEST_INCLUDES 22# ------------------------- 23AC_DEFUN([gl_YEAR2038_TEST_INCLUDES], 24[[ 25 #include <time.h> 26 /* Check that time_t can represent 2**32 - 1 correctly. */ 27 #define LARGE_TIME_T \\ 28 ((time_t) (((time_t) 1 << 30) - 1 + 3 * ((time_t) 1 << 30))) 29 int verify_time_t_range[(LARGE_TIME_T / 65537 == 65535 30 && LARGE_TIME_T % 65537 == 0) 31 ? 1 : -1]; 32]]) 33 34# gl_YEAR2038_BODY(REQUIRE-YEAR2038-SAFE) 35----------------------------------------- 36AC_DEFUN([gl_YEAR2038_BODY], 37[ 38 AC_ARG_ENABLE([year2038], 39 [ --disable-year2038 omit support for timestamps past the year 2038]) 40 AS_IF([test "$enable_year2038" != no], 41 [ 42 dnl On many systems, time_t is already a 64-bit type. 43 dnl On those systems where time_t is still 32-bit, it requires kernel 44 dnl and libc support to make it 64-bit. For glibc 2.34 and later on Linux, 45 dnl defining _TIME_BITS=64 and _FILE_OFFSET_BITS=64 is needed on x86 and ARM. 46 dnl 47 dnl On native Windows, the system include files define types __time32_t 48 dnl and __time64_t. By default, time_t is an alias of 49 dnl - __time32_t on 32-bit mingw, 50 dnl - __time64_t on 64-bit mingw and on MSVC (since MSVC 8). 51 dnl But when compiling with -D__MINGW_USE_VC2005_COMPAT, time_t is an 52 dnl alias of __time64_t. 53 dnl And when compiling with -D_USE_32BIT_TIME_T, time_t is an alias of 54 dnl __time32_t. 55 AC_CACHE_CHECK([for time_t past the year 2038], [gl_cv_type_time_t_y2038], 56 [AC_COMPILE_IFELSE( 57 [AC_LANG_SOURCE([gl_YEAR2038_TEST_INCLUDES])], 58 [gl_cv_type_time_t_y2038=yes], [gl_cv_type_time_t_y2038=no]) 59 ]) 60 if test "$gl_cv_type_time_t_y2038" = no; then 61 AC_CACHE_CHECK([for 64-bit time_t with _TIME_BITS=64], 62 [gl_cv_type_time_t_bits_macro], 63 [AC_COMPILE_IFELSE( 64 [AC_LANG_SOURCE([[#define _TIME_BITS 64 65 #define _FILE_OFFSET_BITS 64 66 ]gl_YEAR2038_TEST_INCLUDES])], 67 [gl_cv_type_time_t_bits_macro=yes], 68 [gl_cv_type_time_t_bits_macro=no]) 69 ]) 70 if test "$gl_cv_type_time_t_bits_macro" = yes; then 71 AC_DEFINE([_TIME_BITS], [64], 72 [Number of bits in a timestamp, on hosts where this is settable.]) 73 dnl AC_SYS_LARGFILE also defines this; it's OK if we do too. 74 AC_DEFINE([_FILE_OFFSET_BITS], [64], 75 [Number of bits in a file offset, on hosts where this is settable.]) 76 gl_cv_type_time_t_y2038=yes 77 fi 78 fi 79 if test $gl_cv_type_time_t_y2038 = no; then 80 AC_COMPILE_IFELSE( 81 [AC_LANG_SOURCE( 82 [[#ifdef _USE_32BIT_TIME_T 83 int ok; 84 #else 85 error fail 86 #endif 87 ]])], 88 [AC_MSG_FAILURE( 89 [The 'time_t' type stops working after January 2038. 90 Remove _USE_32BIT_TIME_T from the compiler flags.])], 91 [# If not cross-compiling and $1 says we should check, 92 # and 'touch' works with a large timestamp, then evidently wider time_t 93 # is desired and supported, so fail and ask the builder to fix the 94 # problem. Otherwise, just warn the builder. 95 m4_ifval([$1], 96 [if test $cross_compiling = no \ 97 && TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null; then 98 case `TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null` in 99 *'Feb 7 2106'* | *'Feb 7 17:10'*) 100 AC_MSG_FAILURE( 101 [The 'time_t' type stops working after January 2038, 102 and your system appears to support a wider 'time_t'. 103 Try configuring with 'CC="${CC} -m64"'. 104 To build with a 32-bit time_t anyway (not recommended), 105 configure with '--disable-year2038'.]);; 106 esac 107 rm -f conftest.time 108 fi]) 109 if test "$gl_warned_about_y2038" != yes; then 110 AC_MSG_WARN( 111 [The 'time_t' type stops working after January 2038, 112 and this package needs a wider 'time_t' type 113 if there is any way to access timestamps after that. 114 Configure with 'CC="${CC} -m64"' perhaps?]) 115 gl_warned_about_y2038=yes 116 fi 117 ]) 118 fi]) 119]) 120 121AC_DEFUN([gl_YEAR2038], 122[ 123 gl_YEAR2038_BODY([require-year2038-safe]) 124]) 125