__aeabi_ldivmod: fix sign logic
[minix.git] / lib / libc / sys-minix / pread.c
blobf2b751544e78ffc9bf1f2198c05d2b5846af484c
1 #include <sys/cdefs.h>
2 #include "namespace.h"
3 #include <lib.h>
5 #include <unistd.h>
7 #ifdef __weak_alias
8 __weak_alias(pread, _pread)
9 #endif
11 #include <lib.h>
12 #include <unistd.h>
13 #include <minix/u64.h>
15 ssize_t pread64(int fd, void *buffer, size_t nbytes, u64_t where)
17 u64_t here;
18 ssize_t r;
20 if (lseek64(fd, make64(0,0), SEEK_CUR, &here) < 0) return(-1);
21 if (lseek64(fd, where, SEEK_SET, NULL) < 0) return(-1);
22 if ((r = read(fd, buffer, nbytes)) < 0) {
23 int e = errno;
24 lseek64(fd, here, SEEK_SET, NULL);
25 errno = e;
26 return(-1);
29 if (lseek64(fd, here, SEEK_SET, NULL) < 0) return(-1);
31 return(r);
34 ssize_t pread(int fd, void *buffer, size_t nbytes, off_t where)
36 off_t here;
37 ssize_t r;
39 if((here = lseek(fd, 0, SEEK_CUR)) < 0)
40 return -1;
42 if(lseek(fd, where, SEEK_SET) < 0)
43 return -1;
45 if((r=read(fd, buffer, nbytes)) < 0) {
46 int e = errno;
47 lseek(fd, here, SEEK_SET);
48 errno = e;
49 return -1;
52 if(lseek(fd, here, SEEK_SET) < 0)
53 return -1;
55 return r;