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/writenclose_unsafe.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/libstddjb/writenclose_unsafe.c (limited to 'src/libstddjb/writenclose_unsafe.c') diff --git a/src/libstddjb/writenclose_unsafe.c b/src/libstddjb/writenclose_unsafe.c new file mode 100644 index 0000000..f71caea --- /dev/null +++ b/src/libstddjb/writenclose_unsafe.c @@ -0,0 +1,18 @@ +/* ISC license. */ + +#include +#include +#include +#include + +int writenclose_unsafe_internal (int fd, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync) +{ + struct stat st ; + if (allwrite(fd, s, len) < len) return 0 ; + if ((dev || ino) && (fstat(fd, &st) < 0)) return 0 ; + if (dosync && (fd_sync(fd) < 0) && (errno != EINVAL)) return 0 ; + fd_close(fd) ; + if (dev) *dev = st.st_dev ; + if (ino) *ino = st.st_ino ; + return 1 ; +} -- cgit v1.2.3