From c005b541bf9d54327ff860aad88367b854bae3d8 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 9 Jun 2023 13:32:27 +0000 Subject: Add devino, refactor openwrite(v)nclose Signed-off-by: Laurent Bercot --- src/libstddjb/openwritenclose_suffix6.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/libstddjb/openwritenclose_suffix6.c (limited to 'src/libstddjb/openwritenclose_suffix6.c') diff --git a/src/libstddjb/openwritenclose_suffix6.c b/src/libstddjb/openwritenclose_suffix6.c new file mode 100644 index 0000000..be92a87 --- /dev/null +++ b/src/libstddjb/openwritenclose_suffix6.c @@ -0,0 +1,23 @@ +/* ISC license. */ + +#include +#include + +#include +#include + +int openwritenclose_suffix6 (char const *fn, char const *s, size_t n, devino *devino, unsigned int options, char const *suffix) +{ + size_t len = strlen(fn) ; + size_t suffixlen = strlen(suffix) ; + char tmp[len + suffixlen + 1] ; + memcpy(tmp, fn, len) ; + memcpy(tmp + len, suffix, suffixlen + 1) ; + if (!openwritenclose_unsafe5(tmp, s, n, devino, options)) return 0 ; + if (rename(tmp, fn) < 0) + { + unlink_void(tmp) ; + return 0 ; + } + return 1 ; +} -- cgit v1.3.1