diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-01-02 20:23:27 +0000 |
---|---|---|
committer | <> | 2015-02-03 17:27:18 +0000 |
commit | 670c2bbcffe873a2b8589ed140c12e7923ef20c0 (patch) | |
tree | 41044880e826d60621a2d636ed71283de5e0e291 /src/pread.c | |
parent | 3b49db406667ee7189b9ea69b9d9e0bdcc43c5b7 (diff) | |
download | file-5.22.tar.gz |
Imported from /home/lorry/working-area/delta_file/file-5.22.tar.gz.file-5.22
Diffstat (limited to 'src/pread.c')
-rw-r--r-- | src/pread.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/pread.c b/src/pread.c index 80498f7..72d3a6b 100644 --- a/src/pread.c +++ b/src/pread.c @@ -1,14 +1,23 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: pread.c,v 1.1 2013/02/18 15:40:59 christos Exp $") +FILE_RCSID("@(#)$File: pread.c,v 1.3 2014/09/15 19:11:25 christos Exp $") #endif /* lint */ #include <fcntl.h> #include <unistd.h> ssize_t -pread(int fd, void *buf, ssize_t len, off_t off) { - if (lseek(fd, off, SEEK_SET) == (off_t)-1) +pread(int fd, void *buf, size_t len, off_t off) { + off_t old; + ssize_t rv; + + if ((old = lseek(fd, off, SEEK_SET)) == -1) + return -1; + + if ((rv = read(fd, buf, len)) == -1) + return -1; + + if (lseek(fd, old, SEEK_SET) == -1) return -1; - return read(fd, buf, len); + return rv; } |