etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libc / sys / pread.c
blobd5dd1e57e56ff939bce261b3d51dc94f4e6ac0c6
1 #include <sys/cdefs.h>
2 #include "namespace.h"
4 #include <errno.h>
5 #include <unistd.h>
7 #ifdef __weak_alias
8 __weak_alias(pread, _pread)
9 #endif
11 ssize_t pread(int fd, void *buffer, size_t nbytes, off_t where)
13 off_t here;
14 ssize_t r;
16 if((here = lseek(fd, 0, SEEK_CUR)) < 0)
17 return -1;
19 if(lseek(fd, where, SEEK_SET) < 0)
20 return -1;
22 if((r=read(fd, buffer, nbytes)) < 0) {
23 int e = errno;
24 lseek(fd, here, SEEK_SET);
25 errno = e;
26 return -1;
29 if(lseek(fd, here, SEEK_SET) < 0)
30 return -1;
32 return r;