largefile.m4 6.5 KB

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