openwritenclose_at.c (392B)
1 /* ISC license. */ 2 3 #include <unistd.h> 4 5 #include <skalibs/allreadwrite.h> 6 #include <skalibs/djbunix.h> 7 #include <skalibs/unix-transactional.h> 8 9 size_t openwritenclose_at (int dirfd, char const *file, char const *s, size_t n) 10 { 11 size_t r ; 12 int fd = openc_truncatb(dirfd, file) ; 13 if (fd < 0) return 0 ; 14 r = allwrite(fd, s, n) ; 15 if (r >= n) fsync(fd) ; 16 fd_close(fd) ; 17 return r ; 18 }