largefile.m4 6.6 KB

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