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