etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libc / sys / pwrite.c
blobd36b1ec21f8f7ab7178e3b795c237bddd8e08916
1 #include <sys/cdefs.h>
2 #include "namespace.h"
4 #include <errno.h>
5 #include <unistd.h>
7 #ifdef __weak_alias
8 __weak_alias(pwrite, _pwrite)
9 #endif
11 ssize_t pwrite(int fd, const void *buffer, size_t nbytes, off_t where)
13 off_t here;
14 ssize_t w;
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((w=write(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 w;