openwritevnclose_at.c (472B)
1 /* ISC license. */ 2 3 #include <sys/uio.h> 4 #include <unistd.h> 5 6 #include <skalibs/allreadwrite.h> 7 #include <skalibs/siovec.h> 8 #include <skalibs/djbunix.h> 9 #include <skalibs/unix-transactional.h> 10 11 size_t openwritevnclose_at (int dirfd, char const *file, struct iovec const *v, unsigned int n) 12 { 13 size_t r ; 14 int fd = openc_truncatb(dirfd, file) ; 15 if (fd < 0) return 0 ; 16 r = allwritev(fd, v, n) ; 17 if (r >= siovec_len(v, n)) fsync(fd) ; 18 fd_close(fd) ; 19 return r ; 20 }