From c365aeb0721d3749bb5f94f09a3ad97ec6131805 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 27 Sep 2017 20:16:01 +0000 Subject: Rewrite openwrite(v)nclose using mkstemp --- src/libstddjb/openwritevnclose_unsafe.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src/libstddjb/openwritevnclose_unsafe.c') diff --git a/src/libstddjb/openwritevnclose_unsafe.c b/src/libstddjb/openwritevnclose_unsafe.c index 4bc7b2b..ddcbfd3 100644 --- a/src/libstddjb/openwritevnclose_unsafe.c +++ b/src/libstddjb/openwritevnclose_unsafe.c @@ -1,32 +1,23 @@ /* ISC license. */ #include -#include #include #include #include -#include #include int openwritevnclose_unsafe_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync) { - struct stat st ; int fd = open_trunc(fn) ; if (fd < 0) return 0 ; - if (allwritev(fd, v, vlen) < siovec_len(v, vlen)) goto fail ; - if ((dev || ino) && (fstat(fd, &st) < 0)) goto fail ; - if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) goto fail ; - fd_close(fd) ; - if (dev) *dev = st.st_dev ; - if (ino) *ino = st.st_ino ; - return 1 ; - - fail: + if (!writevnclose_unsafe_internal(fd, v, vlen, dev, ino, dosync)) { int e = errno ; fd_close(fd) ; unlink(fn) ; errno = e ; + return 0 ; } - return 0 ; + fd_close(fd) ; + return 1 ; } -- cgit v1.2.3