changeset 1804:e86000107a45 HEAD

pread/pwrite doesn't move file offset. make our compat functions restore it
author Timo Sirainen <tss@iki.fi>
date Sun, 05 Oct 2003 21:01:57 +0300
parents 4a61ab6c980d
children 2ef8e4ab3f03
files src/lib/compat.c
diffstat 1 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/compat.c	Sun Oct 05 20:54:19 2003 +0300
+++ b/src/lib/compat.c	Sun Oct 05 21:01:57 2003 +0300
@@ -99,15 +99,33 @@
 #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;
-	return read(fd, buf, count);
+
+	ret = read(fd, buf, count);
+	if (ret < 0)
+		return -1;
+
+	if (lseek(fd, offset, SEEK_SET) < 0)
+		return -1;
+	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;
-	return write(fd, buf, count);
+
+	ret = write(fd, buf, count);
+	if (ret < 0)
+		return -1;
+
+	if (lseek(fd, offset, SEEK_SET) < 0)
+		return -1;
+	return ret;
 }
 #endif