1 #define _GNU_SOURCE
2 #include <unistd.h>
3 #include <sys/uio.h>
4 #include <fcntl.h>
5 #include "syscall.h"
6
pwrite(int fd,const void * buf,size_t size,off_t ofs)7 ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
8 {
9 if (ofs == -1) ofs--;
10 int r = __syscall_cp(SYS_pwritev2, fd,
11 (&(struct iovec){ .iov_base = (void *)buf, .iov_len = size }),
12 1, (long)(ofs), (long)(ofs>>32), RWF_NOAPPEND);
13 if (r != -EOPNOTSUPP && r != -ENOSYS)
14 return __syscall_ret(r);
15 if (fcntl(fd, F_GETFL) & O_APPEND)
16 return __syscall_ret(-EOPNOTSUPP);
17 return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs));
18 }
19