Debian Codegraph @

m4/largefile.m4

raw
1 # largefile.m4
2 # serial 2
3 dnl Copyright 1992-1996, 1998-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 # Enable large files on systems where this is not the default.
10 # Enable support for files on Linux file systems with 64-bit inode numbers.
11
12 # The following macro works around a problem in Autoconf's AC_FUNC_FSEEKO:
13 # It does not set _LARGEFILE_SOURCE=1 on HP-UX/ia64 32-bit, although this
14 # setting of _LARGEFILE_SOURCE is needed so that <stdio.h> declares fseeko
15 # and ftello in C++ mode as well.
16 # This problem occurs in Autoconf 2.71 and earlier, which lack AC_SYS_YEAR2038.
17 AC_DEFUN([gl_SET_LARGEFILE_SOURCE],
18 m4_ifndef([AC_SYS_YEAR2038], [[
19 AC_REQUIRE([AC_CANONICAL_HOST])
20 AC_FUNC_FSEEKO
21 case "$host_os" in
22 hpux*)
23 AC_DEFINE([_LARGEFILE_SOURCE], [1],
24 [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).])
25 ;;
26 esac
27 ]])
28 )
29
30 dnl Remove AC_SYS_YEAR2038_RECOMMENDED if unpatched Autoconf 2.72 or earlier.
31 dnl Autoconf 2.72 still uses -n32, which is not a C preprocessor option,
32 dnl and which was useful only on IRIX which is no longer supported.
33 dnl This should be fixed in Autoconf 2.73.
34 m4_ifdef([AC_SYS_YEAR2038_RECOMMENDED],
35 [m4_bmatch(m4_ifdef([_AC_SYS_LARGEFILE_OPTIONS],
36 [m4_defn([_AC_SYS_LARGEFILE_OPTIONS])],
37 ["-n32"]),
38 ["-n32"],
39 [m4_undefine([AC_SYS_YEAR2038_RECOMMENDED])])])
40
41 m4_ifndef([AC_SYS_YEAR2038_RECOMMENDED], [
42 # Fix up AC_SYS_YEAR2038_RECOMMENDED and related macros, even if
43 # unpatched Autoconf 2.72 or earlier. This code is taken from Autoconf master.
44
45 # _AC_SYS_YEAR2038_TEST_CODE
46 # --------------------------
47 # C code used to probe for time_t that can represent time points more
48 # than 2**31 - 1 seconds after the epoch. With the usual Unix epoch,
49 # these correspond to dates after 2038-01-18 22:14:07 +0000 (Gregorian),
50 # hence the name.
51 AC_DEFUN([_AC_SYS_YEAR2038_TEST_CODE],
52 [[
53 #include <time.h>
54 /* Check that time_t can represent 2**32 - 1 correctly. */
55 #define LARGE_TIME_T \\
56 ((time_t) (((time_t) 1 << 30) - 1 + 3 * ((time_t) 1 << 30)))
57 int verify_time_t_range[(LARGE_TIME_T / 65537 == 65535
58 && LARGE_TIME_T % 65537 == 0)
59 ? 1 : -1];
60 ]])
61
62 # _AC_SYS_YEAR2038_OPTIONS
63 # ------------------------
64 # List of known ways to enable support for large time_t. If you change
65 # this list you probably also need to change the AS_CASE at the end of
66 # _AC_SYS_YEAR2038_PROBE.
67 m4_define([_AC_SYS_YEAR2038_OPTIONS], m4_normalize(
68 ["none needed"] dnl 64-bit and newer 32-bit Unix
69 ["-D_TIME_BITS=64"] dnl glibc 2.34 with some 32-bit ABIs
70 ["-D__MINGW_USE_VC2005_COMPAT"] dnl 32-bit MinGW
71 ["-U_USE_32_BIT_TIME_T -D__MINGW_USE_VC2005_COMPAT"]
72 dnl 32-bit MinGW (misconfiguration)
73 ))
74
75 # _AC_SYS_YEAR2038_PROBE
76 # ----------------------
77 # Subroutine of AC_SYS_YEAR2038. Probe for time_t that can represent
78 # time points more than 2**31 - 1 seconds after the epoch (dates after
79 # 2038-01-18, see above) and set the cache variable ac_cv_sys_year2038_opts
80 # to one of the values in the _AC_SYS_YEAR2038_OPTIONS list, or to
81 # "support not detected" if none of them worked. Then, set compilation
82 # options and #defines as necessary to enable large time_t support.
83 #
84 # Note that we do not test whether mktime, localtime, etc. handle
85 # large values of time_t correctly, as that would require use of
86 # AC_TRY_RUN. Note also that some systems only support large time_t
87 # together with large off_t.
88 #
89 # If you change this macro you may also need to change
90 # _AC_SYS_YEAR2038_OPTIONS.
91 AC_DEFUN([_AC_SYS_YEAR2038_PROBE],
92 [AC_CACHE_CHECK([for $CC option to support timestamps after 2038],
93 [ac_cv_sys_year2038_opts],
94 [ac_save_CPPFLAGS="$CPPFLAGS"
95 ac_opt_found=no
96 for ac_opt in _AC_SYS_YEAR2038_OPTIONS; do
97 AS_IF([test x"$ac_opt" != x"none needed"],
98 [CPPFLAGS="$ac_save_CPPFLAGS $ac_opt"])
99 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_YEAR2038_TEST_CODE])],
100 [ac_cv_sys_year2038_opts="$ac_opt"
101 ac_opt_found=yes])
102 test $ac_opt_found = no || break
103 done
104 CPPFLAGS="$ac_save_CPPFLAGS"
105 test $ac_opt_found = yes || ac_cv_sys_year2038_opts="support not detected"])
106
107 ac_have_year2038=yes
108 AS_CASE([$ac_cv_sys_year2038_opts],
109 ["none needed"], [],
110 ["support not detected"],
111 [ac_have_year2038=no],
112
113 ["-D_TIME_BITS=64"],
114 [AC_DEFINE([_TIME_BITS], [64],
115 [Number of bits in time_t, on hosts where this is settable.])],
116
117 ["-D__MINGW_USE_VC2005_COMPAT"],
118 [AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
119 [Define to 1 on platforms where this makes time_t a 64-bit type.])],
120
121 ["-U_USE_32_BIT_TIME_T"*],
122 [AC_MSG_FAILURE(m4_text_wrap(
123 [the 'time_t' type is currently forced to be 32-bit.
124 It will stop working after mid-January 2038.
125 Remove _USE_32BIT_TIME_T from the compiler flags.],
126 [], [], [55]))],
127
128 [AC_MSG_ERROR(
129 [internal error: bad value for \$ac_cv_sys_year2038_opts])])
130 ])
131
132 # _AC_SYS_YEAR2038_ENABLE
133 # -----------------------
134 # Depending on which of the YEAR2038 macros was used, add either an
135 # --enable-year2038 or a --disable-year2038 to
136 # the configure script. This is expanded very late and
137 # therefore there cannot be any code in the AC_ARG_ENABLE. The
138 # default value for 'enable_year2038' is emitted unconditionally
139 # because the generated code always looks at this variable.
140 m4_define([_AC_SYS_YEAR2038_ENABLE],
141 [m4_divert_text([DEFAULTS],
142 m4_provide_if([AC_SYS_YEAR2038],
143 [enable_year2038=yes],
144 [enable_year2038=no]))]dnl
145 [AC_ARG_ENABLE([year2038],
146 m4_provide_if([AC_SYS_YEAR2038],
147 [AS_HELP_STRING([--disable-year2038],
148 [don't support timestamps after 2038])],
149 [AS_HELP_STRING([--enable-year2038],
150 [support timestamps after 2038])]))])
151
152 # AC_SYS_YEAR2038
153 # ---------------
154 # Attempt to detect and activate support for large time_t.
155 # On systems where time_t is not always 64 bits, this probe can be
156 # skipped by passing the --disable-year2038 option to configure.
157 AC_DEFUN([AC_SYS_YEAR2038],
158 [AC_REQUIRE([AC_SYS_LARGEFILE])dnl
159 AS_IF([test "$enable_year2038,$ac_have_year2038,$cross_compiling" = yes,no,no],
160 [# If we're not cross compiling and 'touch' works with a large
161 # timestamp, then we can presume the system supports wider time_t
162 # *somehow* and we just weren't able to detect it. One common
163 # case that we deliberately *don't* probe for is a system that
164 # supports both 32- and 64-bit ABIs but only the 64-bit ABI offers
165 # wide time_t. (It would be inappropriate for us to override an
166 # intentional use of -m32.) Error out, demanding use of
167 # --disable-year2038 if this is intentional.
168 AS_IF([TZ=UTC0 touch -t 210602070628.15 conftest.time 2>/dev/null],
169 [AS_CASE([`TZ=UTC0 LC_ALL=C ls -l conftest.time 2>/dev/null`],
170 [*'Feb 7 2106'* | *'Feb 7 17:10'*],
171 [AC_MSG_FAILURE(m4_text_wrap(
172 [this system appears to support timestamps after mid-January 2038,
173 but no mechanism for enabling wide 'time_t' was detected.
174 Did you mean to build a 64-bit binary? (E.g., 'CC="${CC} -m64"'.)
175 To proceed with 32-bit time_t, configure with '--disable-year2038'.],
176 [], [], [55]))])])])])
177
178 # AC_SYS_YEAR2038_RECOMMENDED
179 # ---------------------------
180 # Same as AC_SYS_YEAR2038, but recommend support for large time_t.
181 # If we cannot find any way to make time_t capable of representing
182 # values larger than 2**31 - 1, error out unless --disable-year2038 is given.
183 AC_DEFUN([AC_SYS_YEAR2038_RECOMMENDED],
184 [AC_REQUIRE([AC_SYS_YEAR2038])dnl
185 AS_IF([test "$enable_year2038,$ac_have_year2038" = yes,no],
186 [AC_MSG_FAILURE(m4_text_wrap(
187 [could not enable timestamps after mid-January 2038.
188 This package recommends support for these later timestamps.
189 However, to proceed with signed 32-bit time_t even though it
190 will fail then, configure with '--disable-year2038'.],
191 [], [], [55]))])])
192
193 # _AC_SYS_LARGEFILE_TEST_CODE
194 # ---------------------------
195 # C code used to probe for large file support.
196 m4_define([_AC_SYS_LARGEFILE_TEST_CODE],
197 [@%:@include <sys/types.h>
198 @%:@ifndef FTYPE
199 @%:@ define FTYPE off_t
200 @%:@endif
201 /* Check that FTYPE can represent 2**63 - 1 correctly.
202 We can't simply define LARGE_FTYPE to be 9223372036854775807,
203 since some C++ compilers masquerading as C compilers
204 incorrectly reject 9223372036854775807. */
205 @%:@define LARGE_FTYPE (((FTYPE) 1 << 31 << 31) - 1 + ((FTYPE) 1 << 31 << 31))
206 int FTYPE_is_large[[(LARGE_FTYPE % 2147483629 == 721
207 && LARGE_FTYPE % 2147483647 == 1)
208 ? 1 : -1]];[]dnl
209 ])
210 # Defined by Autoconf 2.71 and circa 2022 Gnulib unwisely depended on it.
211 m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], [_AC_SYS_LARGEFILE_TEST_CODE])
212
213 # _AC_SYS_LARGEFILE_OPTIONS
214 # -------------------------
215 # List of known ways to enable support for large files. If you change
216 # this list you probably also need to change the AS_CASE at the end of
217 # _AC_SYS_LARGEFILE_PROBE.
218 m4_define([_AC_SYS_LARGEFILE_OPTIONS], m4_normalize(
219 ["none needed"] dnl Most current systems
220 ["-D_FILE_OFFSET_BITS=64"] dnl X/Open LFS spec
221 ["-D_LARGE_FILES=1"] dnl 32-bit AIX 4.2.1+, 32-bit z/OS
222 ))
223
224 # _AC_SYS_LARGEFILE_PROBE
225 # -----------------------
226 # Subroutine of AC_SYS_LARGEFILE. Probe for large file support and set
227 # the cache variable ac_cv_sys_largefile_opts to one of the values in
228 # the _AC_SYS_LARGEFILE_OPTIONS list, or to "support not detected" if
229 # none of the options in that list worked. Then, set compilation
230 # options and #defines as necessary to enable large file support.
231 #
232 # If large file support is not detected, the behavior depends on which of
233 # the top-level AC_SYS_LARGEFILE macros was used (see below).
234 #
235 # If you change this macro you may also need to change
236 # _AC_SYS_LARGEFILE_OPTIONS.
237 AC_DEFUN([_AC_SYS_LARGEFILE_PROBE],
238 [AC_CACHE_CHECK([for $CC option to support large files],
239 [ac_cv_sys_largefile_opts],
240 [ac_save_CPPFLAGS=$CPPFLAGS
241 ac_opt_found=no
242 for ac_opt in _AC_SYS_LARGEFILE_OPTIONS; do
243 AS_IF([test x"$ac_opt" != x"none needed"],
244 [CPPFLAGS="$ac_save_CPPFLAGS $ac_opt"])
245 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_CODE])],
246 [AS_IF([test x"$ac_opt" = x"none needed"],
247 [# GNU/Linux s390x and alpha need _FILE_OFFSET_BITS=64 for wide ino_t.
248 CPPFLAGS="$CPPFLAGS -DFTYPE=ino_t"
249 AC_COMPILE_IFELSE([], [],
250 [CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
251 AC_COMPILE_IFELSE([], [ac_opt='-D_FILE_OFFSET_BITS=64'])])])
252 ac_cv_sys_largefile_opts=$ac_opt
253 ac_opt_found=yes])
254 test $ac_opt_found = no || break
255 done
256 CPPFLAGS=$ac_save_CPPFLAGS
257 dnl Gnulib implements large file support for native Windows, based on the
258 dnl variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE.
259 m4_ifdef([gl_LARGEFILE], [
260 AC_REQUIRE([AC_CANONICAL_HOST])
261 if test $ac_opt_found != yes; then
262 AS_CASE([$host_os],
263 [mingw* | windows*],
264 [ac_cv_sys_largefile_opts="supported through gnulib"
265 ac_opt_found=yes]
266 )
267 fi
268 ])
269 test $ac_opt_found = yes || ac_cv_sys_largefile_opts="support not detected"])
270
271 ac_have_largefile=yes
272 AS_CASE([$ac_cv_sys_largefile_opts],
273 ["none needed"], [],
274 ["supported through gnulib"], [],
275 ["support not detected"],
276 [ac_have_largefile=no],
277
278 ["-D_FILE_OFFSET_BITS=64"],
279 [AC_DEFINE([_FILE_OFFSET_BITS], [64],
280 [Number of bits in a file offset, on hosts where this is settable.])],
281
282 ["-D_LARGE_FILES=1"],
283 [AC_DEFINE([_LARGE_FILES], [1],
284 [Define to 1 on platforms where this makes off_t a 64-bit type.])],
285
286 [AC_MSG_ERROR(
287 [internal error: bad value for \$ac_cv_sys_largefile_opts])])
288
289 AS_IF([test "$enable_year2038" != no],
290 [_AC_SYS_YEAR2038_PROBE])
291 AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE])])
292
293 # AC_SYS_LARGEFILE
294 # ----------------
295 # By default, many hosts won't let programs access large files;
296 # one must use special compiler options to get large-file access to work.
297 # For more details about this brain damage please see:
298 # http://www.unix.org/version2/whatsnew/lfs20mar.html
299 # Additionally, on Linux file systems with 64-bit inodes a file that happens
300 # to have a 64-bit inode number cannot be accessed by 32-bit applications on
301 # Linux x86/x86_64. This can occur with file systems such as XFS and NFS.
302 AC_DEFUN([AC_SYS_LARGEFILE],
303 [AC_ARG_ENABLE([largefile],
304 [AS_HELP_STRING([--disable-largefile],
305 [omit support for large files])])dnl
306 AS_IF([test "$enable_largefile,$enable_year2038" != no,no],
307 [_AC_SYS_LARGEFILE_PROBE])])
308 ])# m4_ifndef AC_SYS_YEAR2038_RECOMMENDED
309
310 # Enable large files on systems where this is implemented by Gnulib, not by the
311 # system headers.
312 # Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib
313 # overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively.
314 AC_DEFUN([gl_LARGEFILE],
315 [
316 AC_REQUIRE([AC_CANONICAL_HOST])
317 case "$host_os" in
318 mingw* | windows*)
319 dnl Native Windows.
320 dnl mingw64 defines off_t to a 64-bit type already, if
321 dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE.
322 AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64],
323 [AC_COMPILE_IFELSE(
324 [AC_LANG_PROGRAM(
325 [[#include <sys/types.h>
326 int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
327 ]],
328 [[]])],
329 [gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no])
330 ])
331 if test $gl_cv_type_off_t_64 = no; then
332 WINDOWS_64_BIT_OFF_T=1
333 else
334 WINDOWS_64_BIT_OFF_T=0
335 fi
336 dnl Some mingw versions define, if _FILE_OFFSET_BITS=64, 'struct stat'
337 dnl to 'struct _stat32i64' or 'struct _stat64' (depending on
338 dnl _USE_32BIT_TIME_T), which has a 32-bit st_size member.
339 AC_CACHE_CHECK([for 64-bit st_size], [gl_cv_member_st_size_64],
340 [AC_COMPILE_IFELSE(
341 [AC_LANG_PROGRAM(
342 [[#include <sys/types.h>
343 struct stat buf;
344 int verify_st_size_size[sizeof (buf.st_size) >= 8 ? 1 : -1];
345 ]],
346 [[]])],
347 [gl_cv_member_st_size_64=yes], [gl_cv_member_st_size_64=no])
348 ])
349 if test $gl_cv_member_st_size_64 = no; then
350 WINDOWS_64_BIT_ST_SIZE=1
351 else
352 WINDOWS_64_BIT_ST_SIZE=0
353 fi
354 ;;
355 *)
356 dnl Nothing to do on gnulib's side.
357 dnl A 64-bit off_t is
358 dnl - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX,
359 dnl OSF/1, Cygwin,
360 dnl - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on
361 dnl glibc, HP-UX, Solaris,
362 dnl - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX,
363 dnl - impossible to achieve on Minix 3.1.8.
364 WINDOWS_64_BIT_OFF_T=0
365 WINDOWS_64_BIT_ST_SIZE=0
366 ;;
367 esac
368 ])