From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/openwritenclose_unsafe.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/libstddjb/openwritenclose_unsafe.c (limited to 'src/libstddjb/openwritenclose_unsafe.c') diff --git a/src/libstddjb/openwritenclose_unsafe.c b/src/libstddjb/openwritenclose_unsafe.c new file mode 100644 index 0000000..427f6a6 --- /dev/null +++ b/src/libstddjb/openwritenclose_unsafe.c @@ -0,0 +1,32 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include + +int openwritenclose_unsafe_internal (char const *fn, char const *s, unsigned int len, uint64 *dev, uint64 *ino, int dosync) +{ + struct stat st ; + int fd = open_trunc(fn) ; + if (fd < 0) return 0 ; + if (allwrite(fd, s, len) < len) 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 = (uint64)st.st_dev ; + if (ino) *ino = (uint64)st.st_ino ; + return 1 ; + + fail: + { + register int e = errno ; + fd_close(fd) ; + unlink(fn) ; + errno = e ; + } + return 0 ; +} -- cgit v1.2.3