xref: /aosp_15_r20/external/musl/src/unistd/pwrite.c (revision c9945492fdd68bbe62686c5b452b4dc1be3f8453)
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