largefile.m4 15 KB

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