On Feb 14 12:24, Christian Franke via Cygwin wrote: > Christian Franke via Cygwin wrote: > > Testcase: > > [...] > > Upstream bug? > > Possibly not. A closer look shows that the main loop in copy.c:lseek_copy() > expects that SEEK_DATA fails with ENXIO at EOF. > > https://github.com/coreutils/coreutils/blob/v9.6/src/copy.c#L543 > > lseek_copy(..., off_t ext_start, ...) > { > ... > while (0 <= ext_start) { > { > ... > ext_start = lseek (src_fd, dest_pos, SEEK_DATA); > if (ext_start < 0 && errno != ENXIO) > goto cannot_lseek; > } > ... > } > > This works on Linux (checked on Debian 12) but Cygwin returns the offset if > it is equal to the file size. > > Recent POSIX says: > "[ENXIO] The whence argument is SEEK_HOLE or SEEK_DATA, and offset is > greater than or equal to the file size" > https://pubs.opengroup.org/onlinepubs/9799919799/functions/lseek.html > > But (at least older) Linux man pages suggest that Cygwin behavior may be > correct also: > "In the simplest implementation, a filesystem can support the operations by > making ... SEEK_DATA always return offset." > "ENXIO - whence is SEEK_DATA or SEEK_HOLE, and offset is beyond the end of > the file" > https://man7.org/linux/man-pages/man2/lseek.2.html
In terms of "older", this text is still part of https://man7.org/linux/man-pages/man2/lseek.2.html. But we do return ENXIO. However... > Hmm... does "beyond" mean '>=' or '>' ? ...do you think this fixes it? diff --git a/winsup/cygwin/fhandler/base.cc b/winsup/cygwin/fhandler/base.cc index 8f3dbd4ed51a..79dfaaa5987a 100644 --- a/winsup/cygwin/fhandler/base.cc +++ b/winsup/cygwin/fhandler/base.cc @@ -1144,7 +1144,7 @@ fhandler_base::lseek (off_t offset, int whence) return -1; } /* Per Linux man page, ENXIO if offset is beyond EOF */ - if (offset > fsi.EndOfFile.QuadPart) + if (offset >= fsi.EndOfFile.QuadPart) { set_errno (ENXIO); return -1; Corinna -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple