diff options
Diffstat (limited to 'src/libs6/s6_dtally_write.c')
-rw-r--r-- | src/libs6/s6_dtally_write.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libs6/s6_dtally_write.c b/src/libs6/s6_dtally_write.c new file mode 100644 index 0000000..785376a --- /dev/null +++ b/src/libs6/s6_dtally_write.c @@ -0,0 +1,16 @@ +/* ISC license. */ + +#include <string.h> +#include <skalibs/djbunix.h> +#include <s6/s6-supervise.h> + +int s6_dtally_write (char const *sv, s6_dtally_t const *tab, size_t n) +{ + size_t len = strlen(sv) ; + char fn[len + sizeof(S6_DTALLY_FILENAME) + 1] ; + char tmp[n ? S6_DTALLY_PACK * n : 1] ; + memcpy(fn, sv, len) ; + memcpy(fn + len, "/" S6_DTALLY_FILENAME, sizeof(S6_DTALLY_FILENAME) + 1) ; + for (size_t i = 0 ; i < n ; i++) s6_dtally_pack(tmp + i * S6_DTALLY_PACK, tab + i) ; + return openwritenclose_suffix(fn, tmp, n * S6_DTALLY_PACK, ".new") ; +} |