I was initially just going go fix the += Bashism, but this is the safe
and portable way to enable 64-bit off_t. It is not possible to enable it
on some very old systems. erofs_off_t is hardcoded to u64, but I believe
this will still work correctly alongside a 32-bit off_t.
Either way, you don't need HAVE_PREAD64 or HAVE_PWRITE64 because
pread64/pwrite64 are aliases of pread/pwrite when off_t is 64-bit. See
unistd.h and man pread(2).
Signed-off-by: James Le Cuirot <[email protected]>
---
configure.ac | 4 +---
lib/io.c | 20 +-------------------
2 files changed, 2 insertions(+), 22 deletions(-)
diff --git a/configure.ac b/configure.ac
index 4d34e1f..14332ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -251,8 +251,6 @@ AC_CHECK_FUNCS(m4_flatten([
lsetxattr
memset
realpath
- pread64
- pwrite64
pwritev
posix_fadvise
fstatfs
@@ -554,7 +552,7 @@ AS_IF([test "x$with_xxhash" != "xno"], [
])
# Enable 64-bit off_t
-CFLAGS+=" -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+AC_SYS_LARGEFILE
# Configure fuzzing mode
AS_IF([test "x$enable_fuzzing" != "xyes"], [], [
diff --git a/lib/io.c b/lib/io.c
index aa043ca..eaa5fa7 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -74,11 +74,7 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void
*buf,
pos += vf->offset;
do {
-#ifdef HAVE_PWRITE64
- ret = pwrite64(vf->fd, buf, len, (off64_t)pos);
-#else
ret = pwrite(vf->fd, buf, len, (off_t)pos);
-#endif
if (ret <= 0) {
if (!ret)
break;
@@ -208,11 +204,7 @@ ssize_t erofs_io_pread(struct erofs_vfile *vf, void *buf,
u64 pos, size_t len)
pos += vf->offset;
do {
-#ifdef HAVE_PREAD64
- ret = pread64(vf->fd, buf, len, (off64_t)pos);
-#else
ret = pread(vf->fd, buf, len, (off_t)pos);
-#endif
if (ret <= 0) {
if (!ret)
break;
@@ -436,11 +428,7 @@ static ssize_t __erofs_copy_file_range(int fd_in, u64
*off_in,
char *end, *p;
to_read = min_t(size_t, length, sizeof(buf));
-#ifdef HAVE_PREAD64
- read_count = pread64(fd_in, buf, to_read, *off_in);
-#else
read_count = pread(fd_in, buf, to_read, *off_in);
-#endif
if (read_count == 0)
/* End of file reached prematurely. */
return copied;
@@ -455,13 +443,7 @@ static ssize_t __erofs_copy_file_range(int fd_in, u64
*off_in,
/* Write the buffer part which was read to the destination. */
end = buf + read_count;
for (p = buf; p < end; ) {
- ssize_t write_count;
-
-#ifdef HAVE_PWRITE64
- write_count = pwrite64(fd_out, p, end - p, *off_out);
-#else
- write_count = pwrite(fd_out, p, end - p, *off_out);
-#endif
+ ssize_t write_count = pwrite(fd_out, p, end - p,
*off_out);
if (write_count < 0) {
/*
* Adjust the input read position to match what
--
2.51.2