1#include "file.h" 2#ifndef lint
| 1#include "file.h" 2#ifndef lint
|
3FILE_RCSID("@(#)$File: pread.c,v 1.2 2013/04/02 16:23:07 christos Exp $")
| 3FILE_RCSID("@(#)$File: pread.c,v 1.3 2014/09/15 19:11:25 christos Exp $")
|
4#endif /* lint */ 5#include <fcntl.h> 6#include <unistd.h> 7 8ssize_t 9pread(int fd, void *buf, size_t len, off_t off) {
| 4#endif /* lint */ 5#include <fcntl.h> 6#include <unistd.h> 7 8ssize_t 9pread(int fd, void *buf, size_t len, off_t off) {
|
10 if (lseek(fd, off, SEEK_SET) == (off_t)-1)
| 10 off_t old; 11 ssize_t rv; 12 13 if ((old = lseek(fd, off, SEEK_SET)) == -1)
|
11 return -1; 12
| 14 return -1; 15
|
13 return read(fd, buf, len);
| 16 if ((rv = read(fd, buf, len)) == -1) 17 return -1; 18 19 if (lseek(fd, old, SEEK_SET) == -1) 20 return -1; 21 22 return rv;
|
14}
| 23}
|