1 # Enable large files on systems where this is not the default.
2 # Enable support for files on Linux file systems with 64-bit inode numbers.
4 # Copyright 1992-1996, 1998-2023 Free Software Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
9 # The following macro works around a problem in Autoconf's AC_FUNC_FSEEKO:
10 # It does not set _LARGEFILE_SOURCE=1 on HP-UX/ia64 32-bit, although this
11 # setting of _LARGEFILE_SOURCE is needed so that <stdio.h> declares fseeko
12 # and ftello in C++ mode as well.
13 # Fixed in Autoconf 2.72, which has AC_SYS_YEAR2038.
14 AC_DEFUN([gl_SET_LARGEFILE_SOURCE],
15 m4_ifndef([AC_SYS_YEAR2038], [[
16 AC_REQUIRE([AC_CANONICAL_HOST])
20 AC_DEFINE([_LARGEFILE_SOURCE], [1],
21 [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).])
27 # Work around a problem in autoconf <= 2.69:
28 # AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5,
29 # or configures them incorrectly in some cases.
30 m4_version_prereq([2.70], [], [
32 # _AC_SYS_LARGEFILE_TEST_INCLUDES
33 # -------------------------------
34 m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
35 [#include <sys/types.h>
36 /* Check that off_t can represent 2**63 - 1 correctly.
37 We can't simply define LARGE_OFF_T to be 9223372036854775807,
38 since some C++ compilers masquerading as C compilers
39 incorrectly reject 9223372036854775807. */
40 #define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31))
41 int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
42 && LARGE_OFF_T % 2147483647 == 1)
45 ])# m4_version_prereq 2.70
47 # Support AC_SYS_YEAR2038, even if Autoconf 2.71 or earlier.
48 # This code is taken from Autoconf master.
49 m4_ifndef([AC_SYS_YEAR2038], [
51 # _AC_SYS_YEAR2038_TEST_CODE
52 # --------------------------
53 # C code used to probe for time_t that can represent time points more
54 # than 2**31 - 1 seconds after the epoch. With the usual Unix epoch,
55 # these correspond to dates after 2038-01-18 22:14:07 +0000 (Gregorian),
57 AC_DEFUN([_AC_SYS_YEAR2038_TEST_CODE],
60 /* Check that time_t can represent 2**32 - 1 correctly. */
61 #define LARGE_TIME_T \\
62 ((time_t) (((time_t) 1 << 30) - 1 + 3 * ((time_t) 1 << 30)))
63 int verify_time_t_range[(LARGE_TIME_T / 65537 == 65535
64 && LARGE_TIME_T % 65537 == 0)
68 # _AC_SYS_YEAR2038_OPTIONS
69 # ------------------------
70 # List of known ways to enable support for large time_t. If you change
71 # this list you probably also need to change the AS_CASE at the end of
72 # _AC_SYS_YEAR2038_PROBE.
73 m4_define([_AC_SYS_YEAR2038_OPTIONS], m4_normalize(
74 ["none needed"] dnl 64-bit and newer 32-bit Unix
75 ["-D_TIME_BITS=64"] dnl glibc 2.34 with some 32-bit ABIs
76 ["-D__MINGW_USE_VC2005_COMPAT"] dnl 32-bit MinGW
77 ["-U_USE_32_BIT_TIME_T -D__MINGW_USE_VC2005_COMPAT"]
78 dnl 32-bit MinGW (misconfiguration)
81 # _AC_SYS_YEAR2038_PROBE([IF-NOT-DETECTED])
82 # -----------------------------------------
83 # Subroutine of AC_SYS_YEAR2038. Probe for time_t that can represent
84 # time points more than 2**31 - 1 seconds after the epoch (dates after
85 # 2038-01-18, see above) and set the cache variable ac_cv_sys_year2038_opts
86 # to one of the values in the _AC_SYS_YEAR2038_OPTIONS list, or to
87 # "support not detected" if none of them worked. Then, set compilation
88 # options and #defines as necessary to enable large time_t support.
90 # Note that we do not test whether mktime, localtime, etc. handle
91 # large values of time_t correctly, as that would require use of
92 # AC_TRY_RUN. Note also that some systems only support large time_t
93 # together with large off_t.
95 # If support is not detected, the behavior depends on which of the
96 # top-level AC_SYS_YEAR2038 macros was used (see below).
98 # If you change this macro you may also need to change
99 # _AC_SYS_YEAR2038_OPTIONS.
100 AC_DEFUN([_AC_SYS_YEAR2038_PROBE],
101 [AC_CACHE_CHECK([for $CC option to enable timestamps after Jan 2038],
102 [ac_cv_sys_year2038_opts],
103 [ac_save_CPPFLAGS="$CPPFLAGS"
105 for ac_opt in _AC_SYS_YEAR2038_OPTIONS; do
106 AS_IF([test x"$ac_opt" != x"none needed"],
107 [CPPFLAGS="$ac_save_CPPFLAGS $ac_opt"])
108 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_YEAR2038_TEST_CODE])],
109 [ac_cv_sys_year2038_opts="$ac_opt"
111 test $ac_opt_found = no || break
113 CPPFLAGS="$ac_save_CPPFLAGS"
114 test $ac_opt_found = yes || ac_cv_sys_year2038_opts="support not detected"])
117 AS_CASE([$ac_cv_sys_year2038_opts],
119 ["support not detected"],
121 AS_CASE([$enable_year2038],
123 [# If we're not cross compiling and 'touch' works with a large
124 # timestamp, then we can presume the system supports wider time_t
125 # *somehow* and we just weren't able to detect it. One common
126 # case that we deliberately *don't* probe for is a system that
127 # supports both 32- and 64-bit ABIs but only the 64-bit ABI offers
128 # wide time_t. (It would be inappropriate for us to override an
129 # intentional use of -m32.) Error out, demanding use of
130 # --disable-year2038 if this is intentional.
131 AS_IF([test $cross_compiling = no],
132 [AS_IF([TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null],
133 [AS_CASE([`TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null`],
134 [*'Feb 7 2106'* | *'Feb 7 17:10'*],
135 [AC_MSG_FAILURE(m4_text_wrap(
136 [this system appears to support timestamps after January 2038,
137 but no mechanism for enabling wide 'time_t' was detected.
138 Did you mean to build a 64-bit binary? (e.g. 'CC="${CC} -m64"'.)
139 To proceed with 32-bit time_t, configure with '--disable-year2038'.],
140 [], [], [55]))])])])])],
143 [AC_DEFINE([_TIME_BITS], [64],
144 [Number of bits in time_t, on hosts where this is settable.])],
146 ["-D__MINGW_USE_VC2005_COMPAT=1"],
147 [AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
148 [Define to 1 on platforms where this makes time_t a 64-bit type.])],
150 ["-U_USE_32_BIT_TIME_T"*],
151 [AC_MSG_FAILURE(m4_text_wrap(
152 [the 'time_t' type is currently forced to be 32-bit.
153 It will stop working after January 2038.
154 Remove _USE_32BIT_TIME_T from the compiler flags.],
158 [internal error: bad value for \$ac_cv_sys_year2038_opts])])
161 # _AC_SYS_YEAR2038_ENABLE
162 # -----------------------
163 # Subroutine of AC_SYS_YEAR2038 and _AC_SYS_YEAR2038_OPT_IN.
164 # Depending on which of the YEAR2038 macros was used, add either an
165 # --enable-year2038, or a --disable-year2038, or no option at all to
166 # the configure script. Note that this is expanded very late and
167 # therefore there cannot be any code in the AC_ARG_ENABLE. The
168 # default value for enable_year2038 is emitted unconditionally
169 # because the generated code always looks at this variable.
170 m4_define([_AC_SYS_YEAR2038_ENABLE],
171 [m4_divert_text([DEFAULTS],
172 m4_provide_if([AC_SYS_YEAR2038],
173 [enable_year2038=yes],
174 [enable_year2038=no]))]dnl
175 [AC_ARG_ENABLE([year2038],
176 m4_provide_if([AC_SYS_YEAR2038],
177 [AS_HELP_STRING([--disable-year2038],
178 [do not support timestamps after 2038])],
179 [AS_HELP_STRING([--enable-year2038],
180 [support timestamps after 2038])]))])
182 # _AC_SYS_YEAR2038_OPT_IN
183 # -----------------------
184 # If the --enable-year2038 option is given to configure, attempt to
185 # detect and activate support for large time_t on 32-bit systems.
186 # This macro is automatically invoked by AC_SYS_LARGEFILE when large
187 # *file* support is detected. It does not AC_REQUIRE AC_SYS_LARGEFILE
188 # to avoid a dependency loop, and is therefore unsafe to expose as a
190 AC_DEFUN([_AC_SYS_YEAR2038_OPT_IN],
191 [m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl
192 AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE])
193 AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])
198 # Attempt to detect and activate support for large time_t.
199 # On systems where time_t is not always 64 bits, this probe can be
200 # skipped by passing the --disable-year2038 option to configure.
201 AC_DEFUN([AC_SYS_YEAR2038],
202 [AC_REQUIRE([AC_SYS_LARGEFILE])]dnl
203 [m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl
204 AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE])
205 AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])
208 # _AC_SYS_LARGEFILE_TEST_CODE
209 # ---------------------------
210 # C code used to probe for large file support.
211 m4_define([_AC_SYS_LARGEFILE_TEST_CODE],
212 [@%:@include <sys/types.h>
213 /* Check that off_t can represent 2**63 - 1 correctly.
214 We can't simply define LARGE_OFF_T to be 9223372036854775807,
215 since some C++ compilers masquerading as C compilers
216 incorrectly reject 9223372036854775807. */
217 @%:@define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31))
218 int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
219 && LARGE_OFF_T % 2147483647 == 1)
223 # _AC_SYS_LARGEFILE_OPTIONS
224 # -------------------------
225 # List of known ways to enable support for large files. If you change
226 # this list you probably also need to change the AS_CASE at the end of
227 # _AC_SYS_LARGEFILE_PROBE.
228 m4_define([_AC_SYS_LARGEFILE_OPTIONS], m4_normalize(
229 ["none needed"] dnl Most current systems
230 ["-D_FILE_OFFSET_BITS=64"] dnl X/Open LFS spec
231 ["-D_LARGE_FILES=1"] dnl AIX (which versions?)
232 ["-n32"] dnl Irix 6.2 w/ SGI compiler
235 # _AC_SYS_LARGEFILE_PROBE
236 # -----------------------
237 # Subroutine of AC_SYS_LARGEFILE. Probe for large file support and set
238 # the cache variable ac_cv_sys_largefile_opts to one of the values in
239 # the _AC_SYS_LARGEFILE_OPTIONS list, or to "support not detected" if
240 # none of the options in that list worked. Then, set compilation
241 # options and #defines as necessary to enable large file support.
243 # If large file support is not detected, the behavior depends on which of
244 # the top-level AC_SYS_LARGEFILE macros was used (see below).
246 # If you change this macro you may also need to change
247 # _AC_SYS_LARGEFILE_OPTIONS.
248 AC_DEFUN([_AC_SYS_LARGEFILE_PROBE],
249 [AC_CACHE_CHECK([for $CC option to enable large file support],
250 [ac_cv_sys_largefile_opts],
253 for ac_opt in _AC_SYS_LARGEFILE_OPTIONS; do
254 AS_IF([test x"$ac_opt" != x"none needed"],
255 [CC="$ac_save_CC $ac_opt"])
256 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_CODE])],
257 [ac_cv_sys_largefile_opts="$ac_opt"
259 test $ac_opt_found = no || break
262 test $ac_opt_found = yes || ac_cv_sys_largefile_opts="support not detected"])
264 ac_have_largefile=yes
265 AS_CASE([$ac_cv_sys_largefile_opts],
267 ["support not detected"],
268 [ac_have_largefile=no],
270 ["-D_FILE_OFFSET_BITS=64"],
271 [AC_DEFINE([_FILE_OFFSET_BITS], [64],
272 [Number of bits in a file offset, on hosts where this is settable.])],
274 ["-D_LARGE_FILES=1"],
275 [AC_DEFINE([_LARGE_FILES], [1],
276 [Define to 1 on platforms where this makes off_t a 64-bit type.])],
282 [internal error: bad value for \$ac_cv_sys_largefile_opts])])
284 _AC_SYS_YEAR2038_OPT_IN
287 # _AC_SYS_LARGEFILE_ENABLE
288 # ------------------------
289 # Subroutine of AC_SYS_LARGEFILE. Note that this
290 # is expanded very late and therefore there cannot be any code in the
291 # AC_ARG_ENABLE. The default value for enable_largefile is emitted
292 # unconditionally because the generated shell code always looks at
294 m4_define([_AC_SYS_LARGEFILE_ENABLE],
295 [m4_divert_text([DEFAULTS],
296 enable_largefile=yes)]dnl
297 [AC_ARG_ENABLE([largefile],
298 [AS_HELP_STRING([--disable-largefile], [omit support for large files])])])
302 # By default, many hosts won't let programs access large files;
303 # one must use special compiler options to get large-file access to work.
304 # For more details about this brain damage please see:
305 # http://www.unix.org/version2/whatsnew/lfs20mar.html
306 # Additionally, on Linux file systems with 64-bit inodes a file that happens
307 # to have a 64-bit inode number cannot be accessed by 32-bit applications on
308 # Linux x86/x86_64. This can occur with file systems such as XFS and NFS.
309 # This macro allows configuration to continue if the system doesn't support
311 AC_DEFUN([AC_SYS_LARGEFILE],
312 [m4_provide_if([_AC_SYS_LARGEFILE_PROBE], [], [dnl
313 AS_IF([test "$enable_largefile" != no], [_AC_SYS_LARGEFILE_PROBE])
314 AC_CONFIG_COMMANDS_PRE([_AC_SYS_LARGEFILE_ENABLE])
316 ])# m4_ifndef AC_SYS_YEAR2038
318 # Enable large files on systems where this is implemented by Gnulib, not by the
320 # Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib
321 # overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively.
322 AC_DEFUN([gl_LARGEFILE],
324 AC_REQUIRE([AC_CANONICAL_HOST])
328 dnl mingw64 defines off_t to a 64-bit type already, if
329 dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE.
330 AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64],
333 [[#include <sys/types.h>
334 int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
337 [gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no])
339 if test $gl_cv_type_off_t_64 = no; then
340 WINDOWS_64_BIT_OFF_T=1
342 WINDOWS_64_BIT_OFF_T=0
344 dnl Some mingw versions define, if _FILE_OFFSET_BITS=64, 'struct stat'
345 dnl to 'struct _stat32i64' or 'struct _stat64' (depending on
346 dnl _USE_32BIT_TIME_T), which has a 32-bit st_size member.
347 AC_CACHE_CHECK([for 64-bit st_size], [gl_cv_member_st_size_64],
350 [[#include <sys/types.h>
352 int verify_st_size_size[sizeof (buf.st_size) >= 8 ? 1 : -1];
355 [gl_cv_member_st_size_64=yes], [gl_cv_member_st_size_64=no])
357 if test $gl_cv_member_st_size_64 = no; then
358 WINDOWS_64_BIT_ST_SIZE=1
360 WINDOWS_64_BIT_ST_SIZE=0
364 dnl Nothing to do on gnulib's side.
365 dnl A 64-bit off_t is
366 dnl - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX,
368 dnl - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on
369 dnl glibc, HP-UX, Solaris,
370 dnl - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX,
371 dnl - impossible to achieve on Minix 3.1.8.
372 WINDOWS_64_BIT_OFF_T=0
373 WINDOWS_64_BIT_ST_SIZE=0