some coverity fixes.
[minix.git] / lib / libc / sys-minix / pwrite.c
blobf2c07b3a42bc0a32bc9e3f278bb00e674999ceb4
1 #include <sys/cdefs.h>
2 #include "namespace.h"
3 #include <lib.h>
5 #include <unistd.h>
7 #ifdef __weak_alias
8 __weak_alias(pwrite, _pwrite)
9 #endif
11 #include <minix/u64.h>
13 ssize_t pwrite64(int fd, const void *buffer, size_t nbytes, u64_t where)
15 u64_t here;
16 ssize_t w;
18 if (lseek64(fd, make64(0,0), SEEK_CUR, &here) < 0) return(-1);
19 if (lseek64(fd, where, SEEK_SET, NULL) < 0) return(-1);
20 if ((w = write(fd, buffer, nbytes)) < 0) {
21 int e = errno;
22 lseek64(fd, here, SEEK_SET, NULL);
23 errno = e;
24 return(-1);
27 if (lseek64(fd, here, SEEK_SET, NULL) < 0) return(-1);
29 return(w);
32 ssize_t pwrite(int fd, const void *buffer, size_t nbytes, off_t where)
34 off_t here;
35 ssize_t w;
37 if((here = lseek(fd, 0, SEEK_CUR)) < 0)
38 return -1;
40 if(lseek(fd, where, SEEK_SET) < 0)
41 return -1;
43 if((w=write(fd, buffer, nbytes)) < 0) {
44 int e = errno;
45 lseek(fd, here, SEEK_SET);
46 errno = e;
47 return -1;
50 if(lseek(fd, here, SEEK_SET) < 0)
51 return -1;
53 return w;