Debian Codegraph @

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