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