Problem reported by Sudhip Nashi (Bug#51857).
* doc/posix-functions/lseek.texi (lseek): Mention macOS SEEK_DATA
issue.
* lib/lseek.c (rpl_lseek): Work around macOS portability glitch.
* m4/lseek.m4 (gl_FUNC_LSEEK): Replace lseek on Darwin.
* modules/lseek (Depends-on): Depend on msvc-nothrow
and fstat only if needed.
+2021-11-15 Paul Eggert <eggert@cs.ucla.edu>
+
+ lseek: port around macOS SEEK_DATA glitch
+ Problem reported by Sudhip Nashi (Bug#51857).
+ * doc/posix-functions/lseek.texi (lseek): Mention macOS SEEK_DATA
+ issue.
+ * lib/lseek.c (rpl_lseek): Work around macOS portability glitch.
+ * m4/lseek.m4 (gl_FUNC_LSEEK): Replace lseek on Darwin.
+ * modules/lseek (Depends-on): Depend on msvc-nothrow
+ and fstat only if needed.
+
2021-11-11 Fabrice Fontaine <fontaine.fabrice@gmail.com> (tiny change)
sigsegv: fix builds on microblazeel, or1k
Portability problems fixed by Gnulib:
@itemize
@item
+On some platforms, @code{lseek (fd, offset, SEEK_DATA)} returns a value
+greater than @code{offset} even when @code{offset} addresses data:
+macOS 12
+@item
This function is declared in a different header file (namely, @code{<io.h>})
on some platforms:
MSVC 14.
errno = ESPIPE;
return -1;
}
+#elif defined __APPLE__ && defined __MACH__ && defined SEEK_DATA
+ if (whence == SEEK_DATA)
+ {
+ /* If OFFSET points to data, macOS lseek+SEEK_DATA returns the
+ start S of the first data region that begins *after* OFFSET,
+ where the region from OFFSET to S consists of possibly-empty
+ data followed by a possibly-empty hole. To work around this
+ portability glitch, check whether OFFSET is within data by
+ using lseek+SEEK_HOLE, and if so return to OFFSET by using
+ lseek+SEEK_SET. */
+ off_t next_hole = lseek (fd, offset, SEEK_HOLE);
+ if (next_hole < 0)
+ return next_hole;
+ if (next_hole != offset)
+ whence = SEEK_SET;
+ }
#else
/* BeOS lseek mistakenly succeeds on pipes... */
struct stat statbuf;
-# lseek.m4 serial 11
+# lseek.m4 serial 12
dnl Copyright (C) 2007, 2009-2021 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
;;
esac
])
- if test $gl_cv_func_lseek_pipe = no; then
+ if test "$gl_cv_func_lseek_pipe" = no; then
REPLACE_LSEEK=1
AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
[Define to 1 if lseek does not detect pipes.])
if test $WINDOWS_64_BIT_OFF_T = 1; then
REPLACE_LSEEK=1
fi
+
+ dnl macOS SEEK_DATA is incompatible with other platforms.
+ case $host_os in
+ darwin*)
+ REPLACE_LSEEK=1;;
+ esac
])
unistd
sys_types
largefile
-msvc-nothrow [test $REPLACE_LSEEK = 1]
-fstat [test $REPLACE_LSEEK = 1]
+msvc-nothrow [test $WINDOWS_64_BIT_OFF_T = 1]
+fstat [test "$gl_cv_func_lseek_pipe" = no]
configure.ac:
gl_FUNC_LSEEK