git » libjio » commit b76f675

libjio: Handle lseek() failures in jreadv()

author Alberto Bertogli
2009-07-13 05:45:09 UTC
committer Alberto Bertogli
2009-07-13 05:45:09 UTC
parent 96077411ba599c1b0304d8c3ffcb16ad81f6a2ac

libjio: Handle lseek() failures in jreadv()

This patch makes jreadv() handle lseek() failures, and while at it removes
some leftover code.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

libjio/unix.c +5 -6

diff --git a/libjio/unix.c b/libjio/unix.c
index c8d9461..b41dd4f 100644
--- a/libjio/unix.c
+++ b/libjio/unix.c
@@ -57,19 +57,18 @@ ssize_t jpread(struct jfs *fs, void *buf, size_t count, off_t offset)
 /* readv() wrapper */
 ssize_t jreadv(struct jfs *fs, const struct iovec *vector, int count)
 {
-	int rv, i;
-	size_t sum;
+	ssize_t rv;
 	off_t pos;
 
-	sum = 0;
-	for (i = 0; i < count; i++)
-		sum += vector[i].iov_len;
-
 	pthread_mutex_lock(&(fs->lock));
 	pos = lseek(fs->fd, 0, SEEK_CUR);
+	if (pos < 0)
+		return -1;
+
 	plockf(fs->fd, F_LOCKR, pos, count);
 	rv = readv(fs->fd, vector, count);
 	plockf(fs->fd, F_UNLOCK, pos, count);
+
 	pthread_mutex_unlock(&(fs->lock));
 
 	return rv;