summaryrefslogtreecommitdiff
path: root/src/libstddjb/writevnclose_unsafe.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-09-27 20:16:01 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-09-27 20:16:01 +0000
commitc365aeb0721d3749bb5f94f09a3ad97ec6131805 (patch)
tree0a63fa2d7c499b6e835d5665438f1f67cd7db494 /src/libstddjb/writevnclose_unsafe.c
parent1728f7ed8e96a03dd6a75c9668d394562ed63a59 (diff)
downloadskalibs-c365aeb0721d3749bb5f94f09a3ad97ec6131805.tar.xz
Rewrite openwrite(v)nclose using mkstemp
Diffstat (limited to 'src/libstddjb/writevnclose_unsafe.c')
-rw-r--r--src/libstddjb/writevnclose_unsafe.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libstddjb/writevnclose_unsafe.c b/src/libstddjb/writevnclose_unsafe.c
new file mode 100644
index 0000000..9d2348a
--- /dev/null
+++ b/src/libstddjb/writevnclose_unsafe.c
@@ -0,0 +1,20 @@
+/* ISC license. */
+
+#include <sys/uio.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/siovec.h>
+#include <skalibs/djbunix.h>
+
+int writevnclose_unsafe_internal (int fd, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync)
+{
+ struct stat st ;
+ if (allwritev(fd, v, vlen) < siovec_len(v, vlen)) 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 ;
+}