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.
3
4# Copyright 1992-1996, 1998-2021 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.
8
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.
13AC_DEFUN([gl_SET_LARGEFILE_SOURCE],
14[
15  AC_REQUIRE([AC_CANONICAL_HOST])
16  AC_FUNC_FSEEKO
17  case "$host_os" in
18    hpux*)
19      AC_DEFINE([_LARGEFILE_SOURCE], [1],
20        [Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2).])
21      ;;
22  esac
23])
24
25# Work around a problem in Autoconf through at least 2.71 on glibc 2.34+
26# with _TIME_BITS.  Also, work around a problem in autoconf <= 2.69:
27# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5,
28# or configures them incorrectly in some cases.
29m4_version_prereq([2.70], [], [
30
31# _AC_SYS_LARGEFILE_TEST_INCLUDES
32# -------------------------------
33m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES],
34[#include <sys/types.h>
35 /* Check that off_t can represent 2**63 - 1 correctly.
36    We can't simply define LARGE_OFF_T to be 9223372036854775807,
37    since some C++ compilers masquerading as C compilers
38    incorrectly reject 9223372036854775807.  */
39#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31))
40  int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721
41                       && LARGE_OFF_T % 2147483647 == 1)
42                      ? 1 : -1]];[]dnl
43])
44])# m4_version_prereq 2.70
45
46
47# _AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE,
48#                               CACHE-VAR,
49#                               DESCRIPTION,
50#                               PROLOGUE, [FUNCTION-BODY])
51# --------------------------------------------------------
52m4_define([_AC_SYS_LARGEFILE_MACRO_VALUE],
53[AC_CACHE_CHECK([for $1 value needed for large files], [$3],
54[while :; do
55  m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
56    [AC_LANG_PROGRAM([$5], [$6])],
57    [$3=no; break])
58  m4_ifval([$6], [AC_LINK_IFELSE], [AC_COMPILE_IFELSE])(
59    [AC_LANG_PROGRAM([#undef $1
60#define $1 $2
61$5], [$6])],
62    [$3=$2; break])
63  $3=unknown
64  break
65done])
66case $$3 in #(
67  no | unknown) ;;
68  *) AC_DEFINE_UNQUOTED([$1], [$$3], [$4]);;
69esac
70rm -rf conftest*[]dnl
71])# _AC_SYS_LARGEFILE_MACRO_VALUE
72
73
74# AC_SYS_LARGEFILE
75# ----------------
76# By default, many hosts won't let programs access large files;
77# one must use special compiler options to get large-file access to work.
78# For more details about this brain damage please see:
79# http://www.unix.org/version2/whatsnew/lfs20mar.html
80# Additionally, on Linux file systems with 64-bit inodes a file that happens
81# to have a 64-bit inode number cannot be accessed by 32-bit applications on
82# Linux x86/x86_64.  This can occur with file systems such as XFS and NFS.
83AC_DEFUN([AC_SYS_LARGEFILE],
84[AC_ARG_ENABLE(largefile,
85               [  --disable-largefile     omit support for large files])
86AS_IF([test "$enable_largefile" != no],
87 [AC_CACHE_CHECK([for special C compiler options needed for large files],
88    ac_cv_sys_largefile_CC,
89    [ac_cv_sys_largefile_CC=no
90     if test "$GCC" != yes; then
91       ac_save_CC=$CC
92       while :; do
93         # IRIX 6.2 and later do not support large files by default,
94         # so use the C compiler's -n32 option if that helps.
95         AC_LANG_CONFTEST([AC_LANG_PROGRAM([_AC_SYS_LARGEFILE_TEST_INCLUDES])])
96         AC_COMPILE_IFELSE([], [break])
97         CC="$CC -n32"
98         AC_COMPILE_IFELSE([], [ac_cv_sys_largefile_CC=' -n32'; break])
99         break
100       done
101       CC=$ac_save_CC
102       rm -f conftest.$ac_ext
103    fi])
104  if test "$ac_cv_sys_largefile_CC" != no; then
105    CC=$CC$ac_cv_sys_largefile_CC
106  fi
107
108  _AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64,
109    ac_cv_sys_file_offset_bits,
110    [Number of bits in a file offset, on hosts where this is settable.],
111    [_AC_SYS_LARGEFILE_TEST_INCLUDES])
112  AS_CASE([$ac_cv_sys_file_offset_bits],
113    [unknown],
114      [_AC_SYS_LARGEFILE_MACRO_VALUE([_LARGE_FILES], [1],
115         [ac_cv_sys_large_files],
116         [Define for large files, on AIX-style hosts.],
117         [_AC_SYS_LARGEFILE_TEST_INCLUDES])],
118    [64],
119      [gl_YEAR2038_BODY([])])])
120])# AC_SYS_LARGEFILE
121
122# Enable large files on systems where this is implemented by Gnulib, not by the
123# system headers.
124# Set the variables WINDOWS_64_BIT_OFF_T, WINDOWS_64_BIT_ST_SIZE if Gnulib
125# overrides ensure that off_t or 'struct size.st_size' are 64-bit, respectively.
126AC_DEFUN([gl_LARGEFILE],
127[
128  AC_REQUIRE([AC_CANONICAL_HOST])
129  case "$host_os" in
130    mingw*)
131      dnl Native Windows.
132      dnl mingw64 defines off_t to a 64-bit type already, if
133      dnl _FILE_OFFSET_BITS=64, which is ensured by AC_SYS_LARGEFILE.
134      AC_CACHE_CHECK([for 64-bit off_t], [gl_cv_type_off_t_64],
135        [AC_COMPILE_IFELSE(
136           [AC_LANG_PROGRAM(
137              [[#include <sys/types.h>
138                int verify_off_t_size[sizeof (off_t) >= 8 ? 1 : -1];
139              ]],
140              [[]])],
141           [gl_cv_type_off_t_64=yes], [gl_cv_type_off_t_64=no])
142        ])
143      if test $gl_cv_type_off_t_64 = no; then
144        WINDOWS_64_BIT_OFF_T=1
145      else
146        WINDOWS_64_BIT_OFF_T=0
147      fi
148      dnl Some mingw versions define, if _FILE_OFFSET_BITS=64, 'struct stat'
149      dnl to 'struct _stat32i64' or 'struct _stat64' (depending on
150      dnl _USE_32BIT_TIME_T), which has a 32-bit st_size member.
151      AC_CACHE_CHECK([for 64-bit st_size], [gl_cv_member_st_size_64],
152        [AC_COMPILE_IFELSE(
153           [AC_LANG_PROGRAM(
154              [[#include <sys/types.h>
155                struct stat buf;
156                int verify_st_size_size[sizeof (buf.st_size) >= 8 ? 1 : -1];
157              ]],
158              [[]])],
159           [gl_cv_member_st_size_64=yes], [gl_cv_member_st_size_64=no])
160        ])
161      if test $gl_cv_member_st_size_64 = no; then
162        WINDOWS_64_BIT_ST_SIZE=1
163      else
164        WINDOWS_64_BIT_ST_SIZE=0
165      fi
166      ;;
167    *)
168      dnl Nothing to do on gnulib's side.
169      dnl A 64-bit off_t is
170      dnl   - already the default on Mac OS X, FreeBSD, NetBSD, OpenBSD, IRIX,
171      dnl     OSF/1, Cygwin,
172      dnl   - enabled by _FILE_OFFSET_BITS=64 (ensured by AC_SYS_LARGEFILE) on
173      dnl     glibc, HP-UX, Solaris,
174      dnl   - enabled by _LARGE_FILES=1 (ensured by AC_SYS_LARGEFILE) on AIX,
175      dnl   - impossible to achieve on Minix 3.1.8.
176      WINDOWS_64_BIT_OFF_T=0
177      WINDOWS_64_BIT_ST_SIZE=0
178      ;;
179  esac
180])
181