s6_dtally_write.c (549B)
1 /* ISC license. */ 2 3 #include <string.h> 4 #include <skalibs/djbunix.h> 5 #include <s6/supervise.h> 6 7 int s6_dtally_write (char const *sv, s6_dtally_t const *tab, size_t n) 8 { 9 size_t len = strlen(sv) ; 10 char fn[len + sizeof(S6_DTALLY_FILENAME) + 1] ; 11 char tmp[n ? S6_DTALLY_PACK * n : 1] ; 12 memcpy(fn, sv, len) ; 13 memcpy(fn + len, "/" S6_DTALLY_FILENAME, sizeof(S6_DTALLY_FILENAME) + 1) ; 14 for (size_t i = 0 ; i < n ; i++) s6_dtally_pack(tmp + i * S6_DTALLY_PACK, tab + i) ; 15 return openwritenclose_suffix(fn, tmp, n * S6_DTALLY_PACK, ".new") ; 16 }