]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pread/pwrite doesn't move file offset. make our compat functions restore it
authorTimo Sirainen <tss@iki.fi>
Sun, 5 Oct 2003 18:01:57 +0000 (21:01 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 5 Oct 2003 18:01:57 +0000 (21:01 +0300)
--HG--
branch : HEAD

src/lib/compat.c

index e42e009190dbc80beb55163af18972b8ed4baf34..dd0be76f76a807557ac8ce3dfa1c6bde50766c19 100644 (file)
@@ -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