From 422a1f0f54fcf8680b1de74233b3c592df165c5b Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 5 Oct 2003 21:01:57 +0300 Subject: [PATCH] pread/pwrite doesn't move file offset. make our compat functions restore it --HG-- branch : HEAD --- src/lib/compat.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/lib/compat.c b/src/lib/compat.c index e42e009190..dd0be76f76 100644 --- a/src/lib/compat.c +++ b/src/lib/compat.c @@ -99,15 +99,33 @@ ssize_t my_writev(int fd, const struct iovec *iov, int iov_len) #ifndef HAVE_PWRITE ssize_t my_pread(int fd, void *buf, size_t count, off_t offset) { + ssize_t ret; + + if (lseek(fd, offset, SEEK_SET) < 0) + return -1; + + ret = read(fd, buf, count); + if (ret < 0) + return -1; + if (lseek(fd, offset, SEEK_SET) < 0) return -1; - return read(fd, buf, count); + return ret; } ssize_t my_pwrite(int fd, const void *buf, size_t count, off_t offset) { + ssize_t ret; + + if (lseek(fd, offset, SEEK_SET) < 0) + return -1; + + ret = write(fd, buf, count); + if (ret < 0) + return -1; + if (lseek(fd, offset, SEEK_SET) < 0) return -1; - return write(fd, buf, count); + return ret; } #endif -- 2.47.3