]> Savannah Git Hosting - gnulib.git/commitdiff
lseek: avoid SEEK_HOLE bugs in FreeBSD, macOS
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 19 Feb 2023 06:05:24 +0000 (00:05 -0600)
committerBruno Haible <bruno@clisp.org>
Thu, 2 Mar 2023 21:05:46 +0000 (22:05 +0100)
This attempts to fix <https://bugs.gnu.org/61386>, a bug in GNU cp
caused by a serious data corruption bug in FreeBSD and macOS.
* doc/posix-functions/lseek.texi: Mention the bug.
* lib/unistd.in.h (SEEK_DATA, SEEK_HOLE): Undef in macOS < 13 and
FreeBSD < 14.  FreeBSD fixed the bug sometime during FreeBSD 13
<https://bugs.freebsd.org/256205>, so the "FreeBSD < 14" is
conservative.  It’s unknown when Apple will fix macOS so use
macOS "9999" as a placeholder.
* m4/lseek.m4 (gl_FUNC_LSEEK): Replace lseek if on one of the
above platforms.

ChangeLog
doc/posix-functions/lseek.texi
lib/unistd.in.h
m4/lseek.m4

index fe1b99629fdfb13654dce501ccc5c55cf58d3052..4bfb4700bae8aa6c448cf9757a58a9f969ecd499 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2023-02-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+       lseek: avoid SEEK_HOLE bugs in FreeBSD, macOS
+       This attempts to fix <https://bugs.gnu.org/61386>, a bug in GNU cp
+       caused by a serious data corruption bug in FreeBSD and macOS.
+       * doc/posix-functions/lseek.texi: Mention the bug.
+       * lib/unistd.in.h (SEEK_DATA, SEEK_HOLE): Undef in macOS < 13 and
+       FreeBSD < 14.  FreeBSD fixed the bug sometime during FreeBSD 13
+       <https://bugs.freebsd.org/256205>, so the "FreeBSD < 14" is
+       conservative.  It’s unknown when Apple will fix macOS so use
+       macOS "9999" as a placeholder.
+       * m4/lseek.m4 (gl_FUNC_LSEEK): Replace lseek if on one of the
+       above platforms.
+
 2023-02-13  ChuanGang Jiang  <jiangchuanganghw@outlook.com>  (tiny change)
 
        hamt: Detect GCC version correctly.
index 2f8e2b587767eab2874076ad6bff404210c95323..3470524b128cca171166fd2710580a71aaa2ecfc 100644 (file)
@@ -37,4 +37,9 @@ IRIX 6.5.
 @item
 Some systems do not support @code{SEEK_DATA} and @code{SEEK_HOLE}:
 AIX, HP-UX, Microsoft Windows, NetBSD, OpenBSD.
+@item
+Some systems have a buggy @code{SEEK_DATA} and @code{SEEK_HOLE},
+and Gnulib works around the problem via @code{#undef SEEK_DATA}
+and @code{#undef SEEK_HOLE}:
+FreeBSD 13, macOS 12.
 @end itemize
index 50f6e56550e0fe73bd0a7d75db25943a60e10242..69f21c111761ecc1552f96bc45c83d0a70d1cf33 100644 (file)
@@ -1,5 +1,5 @@
 /* Substitute for and wrapper around <unistd.h>.
-   Copyright (C) 2003-2022 Free Software Foundation, Inc.
+   Copyright (C) 2003-2023 Free Software Foundation, Inc.
 
    This file is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as
 # undef _GL_INCLUDING_UNISTD_H
 #endif
 
+/* Avoid lseek bugs in FreeBSD, macOS <https://bugs.gnu.org/61386>.
+   This bug is fixed after FreeBSD 13; see <https://bugs.freebsd.org/256205>.
+   Use macOS "9999" to stand for a future fixed macOS version.  */
+#if defined __FreeBSD__ && __FreeBSD__ < 14
+# undef SEEK_DATA
+# undef SEEK_HOLE
+#elif defined __APPLE__ && defined __MACH__ && defined SEEK_DATA
+# ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
+#  include <AvailabilityMacros.h>
+# endif
+# if (!defined MAC_OS_X_VERSION_MIN_REQUIRED \
+      || MAC_OS_X_VERSION_MIN_REQUIRED < 99990000)
+#  include <sys/fcntl.h> /* It also defines the two macros.  */
+#  undef SEEK_DATA
+#  undef SEEK_HOLE
+# endif
+#endif
+
 /* Get all possible declarations of gethostname().  */
 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
   && !defined _GL_INCLUDING_WINSOCK2_H
index 0583511e82c27bdab360d93ef0a908ed2daf24a7..6e1ab6ffaa0a676e73d69ca4924c6cb7cc286bdd 100644 (file)
@@ -1,5 +1,5 @@
-# lseek.m4 serial 12
-dnl Copyright (C) 2007, 2009-2022 Free Software Foundation, Inc.
+# lseek.m4 serial 13
+dnl Copyright (C) 2007, 2009-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -70,9 +70,29 @@ AC_DEFUN([gl_FUNC_LSEEK],
     REPLACE_LSEEK=1
   fi
 
-  dnl macOS SEEK_DATA is incompatible with other platforms.
-  case $host_os in
-    darwin*)
-      REPLACE_LSEEK=1;;
-  esac
+  AS_IF([test $REPLACE_LSEEK = 0],
+    [AC_CACHE_CHECK([whether SEEK_DATA works but is incompatible with GNU],
+       [gl_cv_func_lseek_works_but_incompatible],
+       [AC_PREPROC_IFELSE(
+          [AC_LANG_SOURCE(
+             dnl Use macOS "9999" to stand for a future fixed macOS version.
+             dnl See ../lib/unistd.in.h and <https://bugs.gnu.org/61386>.
+             [[#include <unistd.h>
+               #if defined __APPLE__ && defined __MACH__ && defined SEEK_DATA
+               # ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
+               #  include <AvailabilityMacros.h>
+               # endif
+               # if 99990000 <= MAC_OS_X_VERSION_MIN_REQUIRED
+               #  define LSEEK_WORKS_BUT_IS_INCOMPATIBLE_WITH_GNU
+               # endif
+               #endif
+               #ifndef LSEEK_WORKS_BUT_IS_INCOMPATIBLE_WITH_GNU
+                #error "No need to work around the bug"
+               #endif
+             ]])],
+          [gl_cv_func_lseek_works_but_incompatible=yes],
+          [gl_cv_func_lseek_works_but_incompatible=no])])
+     if test "$gl_cv_func_lseek_works_but_incompatible" = yes; then
+       REPLACE_LSEEK=1
+     fi])
 ])