largefile.m4 6.8 KB

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