From: Timo Sirainen Date: Sun, 5 Oct 2003 18:01:57 +0000 (+0300) Subject: pread/pwrite doesn't move file offset. make our compat functions restore it X-Git-Tag: 1.1.alpha1~4302 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=422a1f0f54fcf8680b1de74233b3c592df165c5b;p=thirdparty%2Fdovecot%2Fcore.git pread/pwrite doesn't move file offset. make our compat functions restore it --HG-- branch : HEAD --- 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