diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-06-09 13:32:27 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-06-09 13:32:27 +0000 |
commit | c005b541bf9d54327ff860aad88367b854bae3d8 (patch) | |
tree | 6af88b1dd6637084b9e20e0c62b764656b9deaf4 /src/libstddjb/openwritevnclose.c | |
parent | 4af2899ac7ed0da49db7a6e94914fee391212f92 (diff) | |
download | skalibs-c005b541bf9d54327ff860aad88367b854bae3d8.tar.xz |
Add devino, refactor openwrite(v)nclose
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/openwritevnclose.c')
-rw-r--r-- | src/libstddjb/openwritevnclose.c | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/src/libstddjb/openwritevnclose.c b/src/libstddjb/openwritevnclose.c deleted file mode 100644 index 01df3e3..0000000 --- a/src/libstddjb/openwritevnclose.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ISC license. */ - -#include <sys/uio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <skalibs/djbunix.h> - -#define SUFFIX ":skalibs-openwritevnclose:XXXXXX" - -int openwritevnclose_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync) -{ - dev_t tmpdev ; - ino_t tmpino ; - size_t fnlen = strlen(fn) ; - int fd ; - char tmp[fnlen + sizeof(SUFFIX)] ; - memcpy(tmp, fn, fnlen) ; - memcpy(tmp + fnlen, SUFFIX, sizeof(SUFFIX)) ; - fd = mkstemp(tmp) ; - if (fd < 0) return 0 ; - if (!writevnclose_unsafe_internal(fd, v, vlen, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) goto failclose ; - if (rename(tmp, fn) < 0) goto fail ; - if (dev) *dev = tmpdev ; - if (ino) *ino = tmpino ; - return 1 ; - - failclose: - fd_close(fd) ; - fail: - { - int e = errno ; - unlink(tmp) ; - errno = e ; - } - return 0 ; -} |