summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/devino.h18
-rw-r--r--src/include/skalibs/djbunix.h57
-rw-r--r--src/include/skalibs/stddjb.h1
-rw-r--r--src/libstddjb/devino_cmp.c13
-rw-r--r--src/libstddjb/openwritenclose5.c (renamed from src/libstddjb/openwritenclose.c)21
-rw-r--r--src/libstddjb/openwritenclose_internal_deprecated.c13
-rw-r--r--src/libstddjb/openwritenclose_suffix.c29
-rw-r--r--src/libstddjb/openwritenclose_suffix6.c23
-rw-r--r--src/libstddjb/openwritenclose_suffix_internal_deprecated.c13
-rw-r--r--src/libstddjb/openwritenclose_unsafe.c20
-rw-r--r--src/libstddjb/openwritenclose_unsafe5.c20
-rw-r--r--src/libstddjb/openwritenclose_unsafe_internal_deprecated.c13
-rw-r--r--src/libstddjb/openwritevnclose5.c (renamed from src/libstddjb/openwritevnclose.c)21
-rw-r--r--src/libstddjb/openwritevnclose_internal_deprecated.c13
-rw-r--r--src/libstddjb/openwritevnclose_suffix.c30
-rw-r--r--src/libstddjb/openwritevnclose_suffix6.c23
-rw-r--r--src/libstddjb/openwritevnclose_suffix_internal_deprecated.c13
-rw-r--r--src/libstddjb/openwritevnclose_unsafe.c22
-rw-r--r--src/libstddjb/openwritevnclose_unsafe5.c17
-rw-r--r--src/libstddjb/openwritevnclose_unsafe_internal_deprecated.c13
-rw-r--r--src/libstddjb/writenclose_unsafe.c18
-rw-r--r--src/libstddjb/writenclose_unsafe5.c22
-rw-r--r--src/libstddjb/writenclose_unsafe_internal_deprecated.c13
-rw-r--r--src/libstddjb/writevnclose_unsafe.c20
-rw-r--r--src/libstddjb/writevnclose_unsafe5.c23
-rw-r--r--src/libstddjb/writevnclose_unsafe_internal_deprecated.c13
26 files changed, 310 insertions, 192 deletions
diff --git a/src/include/skalibs/devino.h b/src/include/skalibs/devino.h
new file mode 100644
index 0000000..b4feaf3
--- /dev/null
+++ b/src/include/skalibs/devino.h
@@ -0,0 +1,18 @@
+/* ISC license. */
+
+#ifndef SKALIBS_DEVINO_H
+#define SKALIBS_DEVINO_H
+
+#include <sys/types.h>
+
+typedef struct devino_s devino, *devino_ref ;
+struct devino_s
+{
+ dev_t dev ;
+ ino_t ino ;
+} ;
+#define DEVINO_ZERO { .dev = 0, .ino = 0 }
+
+extern int devino_cmp (void const *, void const *) ;
+
+#endif
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h
index 2d2057a..b89a868 100644
--- a/src/include/skalibs/djbunix.h
+++ b/src/include/skalibs/djbunix.h
@@ -10,6 +10,7 @@
#include <skalibs/gccattributes.h>
#include <skalibs/stralloc.h>
+#include <skalibs/devino.h>
extern int coe (int) ;
extern int uncoe (int) ;
@@ -97,53 +98,61 @@ extern ssize_t openreadnclose (char const *, char *, size_t) ;
extern ssize_t openreadnclose_nb (char const *, char *, size_t) ;
extern int openreadfileclose (char const *, stralloc *, size_t) ;
-#define writenclose_unsafe(fd, s, n) writenclose_unsafe_internal(fd, s, (n), 0, 0, 0)
-#define writenclose_unsafe_sync(fd, s, n) writenclose_unsafe_internal(fd, s, (n), 0, 0, 1)
+#define writenclose_unsafe(fd, s, n) writenclose_unsafe5(fd, s, (n), 0)
+#define writenclose_unsafe_sync(fd, s, n) writenclose_unsafe5(fd, s, (n), 0, 1)
#define writenclose_unsafe_devino(fd, s, n, dev, ino) writenclose_unsafe_internal(fd, s, n, dev, (ino), 0)
#define writenclose_unsafe_devino_sync(fd, s, n, dev, ino) writenclose_unsafe_internal(fd, s, n, dev, (ino), 1)
-extern int writenclose_unsafe_internal (int, char const *, size_t, dev_t *, ino_t *, int) ;
+extern int writenclose_unsafe5 (int, char const *, size_t, devino *, unsigned int) ;
+extern int writenclose_unsafe_internal (int, char const *, size_t, dev_t *, ino_t *, int) gccattr_deprecated ;
-#define openwritenclose_unsafe(f, s, n) openwritenclose_unsafe_internal(f, s, (n), 0, 0, 0)
-#define openwritenclose_unsafe_sync(f, s, n) openwritenclose_unsafe_internal(f, s, (n), 0, 0, 1)
+#define openwritenclose_unsafe(f, s, n) openwritenclose_unsafe5(f, s, (n), 0, 0)
+#define openwritenclose_unsafe_sync(f, s, n) openwritenclose_unsafe5(f, s, (n), 0, 1)
#define openwritenclose_unsafe_devino(f, s, n, dev, ino) openwritenclose_unsafe_internal(f, s, n, dev, (ino), 0)
#define openwritenclose_unsafe_devino_sync(f, s, n, dev, ino) openwritenclose_unsafe_internal(f, s, n, dev, (ino), 1)
-extern int openwritenclose_unsafe_internal (char const *, char const *, size_t, dev_t *, ino_t *, int) ;
+extern int openwritenclose_unsafe5 (char const *, char const *, size_t, devino *, unsigned int) ;
+extern int openwritenclose_unsafe_internal (char const *, char const *, size_t, dev_t *, ino_t *, int) gccattr_deprecated ;
-#define openwritenclose_suffix(f, s, n, t) openwritenclose_suffix_internal(f, s, n, 0, 0, 0, t)
-#define openwritenclose_suffix_sync(f, s, n, t) openwritenclose_suffix_internal(f, s, n, 0, 0, 1, t)
+#define openwritenclose_suffix(f, s, n, t) openwritenclose_suffix6(f, s, n, 0, 0, 0, t)
+#define openwritenclose_suffix_sync(f, s, n, t) openwritenclose_suffix6(f, s, n, 0, 0, 1, t)
#define openwritenclose_suffix_devino(f, s, n, t, dev, ino) openwritenclose_suffix_internal(f, s, n, dev, (ino), 0, t)
#define openwritenclose_suffix_devino_sync(f, s, n, t, dev, ino) openwritenclose_suffix_internal(f, s, n, dev, (ino), 1, t)
-extern int openwritenclose_suffix_internal (char const *, char const *, size_t, dev_t *, ino_t *, int, char const *) ;
+extern int openwritenclose_suffix6 (char const *, char const *, size_t, devino *, unsigned int, char const *) ;
+extern int openwritenclose_suffix_internal (char const *, char const *, size_t, dev_t *, ino_t *, int, char const *) gccattr_deprecated ;
-#define openwritenclose(f, s, n) openwritenclose_internal(f, s, (n), 0, 0, 0)
-#define openwritenclose_sync(f, s, n) openwritenclose_internal(f, s, (n), 0, 0, 1)
+#define openwritenclose(f, s, n) openwritenclose5(f, s, (n), 0, 0)
+#define openwritenclose_sync(f, s, n) openwritenclose5(f, s, (n), 0, 1)
#define openwritenclose_devino(f, s, n, dev, ino) openwritenclose_internal(f, s, n, dev, (ino), 0)
#define openwritenclose_devino_sync(f, s, n, dev, ino) openwritenclose_internal(f, s, n, dev, (ino), 1)
-extern int openwritenclose_internal (char const *, char const *, size_t, dev_t *, ino_t *, int) ;
+extern int openwritenclose5 (char const *, char const *, size_t, devino *, unsigned int) ;
+extern int openwritenclose_internal (char const *, char const *, size_t, dev_t *, ino_t *, int) gccattr_deprecated ;
-#define writenvclose_unsafe(fd, v, n) writevnclose_unsafe_internal(fd, v, (n), 0, 0, 0)
-#define writevnclose_unsafe_sync(fd, v, n) writevnclose_unsafe_internal(fd, v, (n), 0, 0, 1)
+#define writenvclose_unsafe(fd, v, n) writevnclose_unsafe5(fd, v, (n), 0, 0)
+#define writevnclose_unsafe_sync(fd, v, n) writevnclose_unsafe5(fd, v, (n), 0, 1)
#define writevnclose_unsafe_devino(fd, v, n, dev, ino) writevnclose_unsafe_internal(fd, v, n, dev, (ino), 0)
#define writevnclose_unsafe_devino_sync(fd, v, n, dev, ino) writevnclose_unsafe_internal(fd, v, n, dev, (ino), 1)
-extern int writevnclose_unsafe_internal (int, struct iovec const *, unsigned int, dev_t *, ino_t *, int) ;
+extern int writevnclose_unsafe5 (int, struct iovec const *, unsigned int, devino *, unsigned int) ;
+extern int writevnclose_unsafe_internal (int, struct iovec const *, unsigned int, dev_t *, ino_t *, int) gccattr_deprecated ;
-#define openwritevnclose_unsafe(f, v, n) openwritevnclose_unsafe_internal(f, v, (n), 0, 0, 0)
-#define openwritevnclose_unsafe_sync(f, v, n) openwritevnclose_unsafe_internal(f, v, (n), 0, 0, 1)
+#define openwritevnclose_unsafe(f, v, n) openwritevnclose_unsafe5(f, v, (n), 0, 0)
+#define openwritevnclose_unsafe_sync(f, v, n) openwritevnclose_unsafe5(f, v, (n), 0, 1)
#define openwritevnclose_unsafe_devino(f, v, n, dev, ino) openwritevnclose_unsafe_internal(f, v, n, dev, (ino), 0)
#define openwritevnclose_unsafe_devino_sync(f, v, n, dev, ino) openwritevnclose_unsafe_internal(f, v, n, dev, (ino), 1)
-extern int openwritevnclose_unsafe_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int) ;
+extern int openwritevnclose_unsafe5 (char const *, struct iovec const *, unsigned int, devino *, unsigned int) ;
+extern int openwritevnclose_unsafe_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int) gccattr_deprecated ;
-#define openwritevnclose_suffix(f, v, n, t) openwritevnclose_suffix_internal(f, v, n, 0, 0, 0, t)
-#define openwritevnclose_suffix_sync(f, v, n, t) openwritevnclose_suffix_internal(f, v, n, 0, 0, 1, t)
+#define openwritevnclose_suffix(f, v, n, t) openwritevnclose_suffix6(f, v, n, 0, 0, t)
+#define openwritevnclose_suffix_sync(f, v, n, t) openwritevnclose_suffix6(f, v, n, 0, 1, t)
#define openwritevnclose_suffix_devino(f, v, n, t, dev, ino) openwritevnclose_suffix_internal(f, v, n, dev, (ino), 0, t)
#define openwritevnclose_suffix_devino_sync(f, v, n, t, dev, ino) openwritevnclose_suffix_internal(f, v, n, dev, (ino), 1, t)
-extern int openwritevnclose_suffix_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int, char const *) ;
+extern int openwritevnclose_suffix6 (char const *, struct iovec const *, unsigned int, devino *, unsigned int, char const *) ;
+extern int openwritevnclose_suffix_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int, char const *) gccattr_deprecated ;
-#define openwritevnclose(f, v, n) openwritevnclose_internal(f, v, (n), 0, 0, 0)
-#define openwritevnclose_sync(f, v, n) openwritevnclose_internal(f, v, (n), 0, 0, 1)
+#define openwritevnclose(f, v, n) openwritevnclose5(f, v, (n), 0, 0)
+#define openwritevnclose_sync(f, v, n) openwritevnclose5(f, v, (n), 0, 1)
#define openwritevnclose_devino(f, v, n, dev, ino) openwritevnclose_internal(f, v, n, dev, (ino), 0)
#define openwritevnclose_devino_sync(f, v, n, dev, ino) openwritevnclose_internal(f, v, n, dev, (ino), 1)
-extern int openwritevnclose_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int) ;
+extern int openwritevnclose5 (char const *, struct iovec const *, unsigned int, devino *, unsigned int) ;
+extern int openwritevnclose_internal (char const *, struct iovec const *, unsigned int, dev_t *, ino_t *, int) gccattr_deprecated ;
extern int rm_rf (char const *) ;
extern int rm_rf_tmp (char const *, stralloc *) ;
diff --git a/src/include/skalibs/stddjb.h b/src/include/skalibs/stddjb.h
index e044895..3ba1a51 100644
--- a/src/include/skalibs/stddjb.h
+++ b/src/include/skalibs/stddjb.h
@@ -20,6 +20,7 @@
#include <skalibs/cbuffer.h>
#include <skalibs/cdb.h>
#include <skalibs/cdbmake.h>
+#include <skalibs/devino.h>
#include <skalibs/direntry.h>
#include <skalibs/diuint32.h>
#include <skalibs/diuint.h>
diff --git a/src/libstddjb/devino_cmp.c b/src/libstddjb/devino_cmp.c
new file mode 100644
index 0000000..567ff6d
--- /dev/null
+++ b/src/libstddjb/devino_cmp.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+
+int devino_cmp (void const *a, void const *b)
+{
+ devino const *aa = a ;
+ devino const *bb = b ;
+ return aa->dev < bb->dev ? -1 :
+ aa->dev > bb->dev ? 1 :
+ aa->ino < bb->ino ? -1 :
+ aa->ino > bb->ino ;
+}
diff --git a/src/libstddjb/openwritenclose.c b/src/libstddjb/openwritenclose5.c
index 427e53e..eef625c 100644
--- a/src/libstddjb/openwritenclose.c
+++ b/src/libstddjb/openwritenclose5.c
@@ -1,38 +1,31 @@
/* ISC license. */
#include <string.h>
-#include <errno.h>
-#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/devino.h>
#include <skalibs/djbunix.h>
#define SUFFIX ":skalibs-openwritenclose:XXXXXX"
-int openwritenclose_internal (char const *fn, char const *s, size_t n, dev_t *dev, ino_t *ino, int dosync)
+int openwritenclose5 (char const *fn, char const *s, size_t n, devino *devino, unsigned int options)
{
- dev_t tmpdev ;
- ino_t tmpino ;
- size_t fnlen = strlen(fn) ;
int fd ;
+ size_t fnlen = strlen(fn) ;
char tmp[fnlen + sizeof(SUFFIX)] ;
memcpy(tmp, fn, fnlen) ;
memcpy(tmp + fnlen, SUFFIX, sizeof(SUFFIX)) ;
fd = mkstemp(tmp) ;
if (fd < 0) return 0 ;
- if (!writenclose_unsafe_internal(fd, s, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) goto failclose ;
+ if (!writenclose_unsafe5(fd, s, n, devino, options)) 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 ;
- }
+ unlink_void(tmp) ;
return 0 ;
}
diff --git a/src/libstddjb/openwritenclose_internal_deprecated.c b/src/libstddjb/openwritenclose_internal_deprecated.c
new file mode 100644
index 0000000..89f8dd2
--- /dev/null
+++ b/src/libstddjb/openwritenclose_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+#include <skalibs/djbunix.h>
+
+int openwritenclose_internal (char const *fn, char const *s, size_t n, dev_t *dev, ino_t *ino, int dosync)
+{
+ devino di ;
+ if (!openwritenclose5(fn, s, n, dev || ino ? &di : 0, !!dosync)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritenclose_suffix.c b/src/libstddjb/openwritenclose_suffix.c
deleted file mode 100644
index 279c19f..0000000
--- a/src/libstddjb/openwritenclose_suffix.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* ISC license. */
-
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <skalibs/djbunix.h>
-
-int openwritenclose_suffix_internal (char const *fn, char const *s, size_t n, dev_t *dev, ino_t *ino, int dosync, char const *suffix)
-{
- dev_t tmpdev ;
- ino_t tmpino ;
- size_t len = strlen(fn) ;
- size_t suffixlen = strlen(suffix) ;
- char tmp[len + suffixlen + 1] ;
- memcpy(tmp, fn, len) ;
- memcpy(tmp + len, suffix, suffixlen + 1) ;
- if (!openwritenclose_unsafe_internal(tmp, s, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) return 0 ;
- if (rename(tmp, fn) < 0)
- {
- int e = errno ;
- unlink(tmp) ;
- errno = e ;
- return 0 ;
- }
- if (dev) *dev = tmpdev ;
- if (ino) *ino = tmpino ;
- return 1 ;
-}
diff --git a/src/libstddjb/openwritenclose_suffix6.c b/src/libstddjb/openwritenclose_suffix6.c
new file mode 100644
index 0000000..be92a87
--- /dev/null
+++ b/src/libstddjb/openwritenclose_suffix6.c
@@ -0,0 +1,23 @@
+/* ISC license. */
+
+#include <string.h>
+#include <stdio.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/djbunix.h>
+
+int openwritenclose_suffix6 (char const *fn, char const *s, size_t n, devino *devino, unsigned int options, char const *suffix)
+{
+ size_t len = strlen(fn) ;
+ size_t suffixlen = strlen(suffix) ;
+ char tmp[len + suffixlen + 1] ;
+ memcpy(tmp, fn, len) ;
+ memcpy(tmp + len, suffix, suffixlen + 1) ;
+ if (!openwritenclose_unsafe5(tmp, s, n, devino, options)) return 0 ;
+ if (rename(tmp, fn) < 0)
+ {
+ unlink_void(tmp) ;
+ return 0 ;
+ }
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritenclose_suffix_internal_deprecated.c b/src/libstddjb/openwritenclose_suffix_internal_deprecated.c
new file mode 100644
index 0000000..95c1fdf
--- /dev/null
+++ b/src/libstddjb/openwritenclose_suffix_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+#include <skalibs/djbunix.h>
+
+int openwritenclose_suffix_internal (char const *fn, char const *s, size_t n, dev_t *dev, ino_t *ino, int dosync, char const *suffix)
+{
+ devino di ;
+ if (!openwritenclose_suffix6(fn, s, n, dev || ino ? &di : 0, !!dosync, suffix)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritenclose_unsafe.c b/src/libstddjb/openwritenclose_unsafe.c
deleted file mode 100644
index 8022f74..0000000
--- a/src/libstddjb/openwritenclose_unsafe.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ISC license. */
-
-#include <errno.h>
-#include <unistd.h>
-#include <skalibs/djbunix.h>
-
-int openwritenclose_unsafe_internal (char const *fn, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync)
-{
- int fd = openc_trunc(fn) ;
- if (fd < 0) return 0 ;
- if (!writenclose_unsafe_internal(fd, s, len, dev, ino, dosync))
- {
- int e = errno ;
- fd_close(fd) ;
- unlink(fn) ;
- errno = e ;
- return 0 ;
- }
- return 1 ;
-}
diff --git a/src/libstddjb/openwritenclose_unsafe5.c b/src/libstddjb/openwritenclose_unsafe5.c
new file mode 100644
index 0000000..45a6b14
--- /dev/null
+++ b/src/libstddjb/openwritenclose_unsafe5.c
@@ -0,0 +1,20 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/djbunix.h>
+
+int openwritenclose_unsafe5 (char const *fn, char const *s, size_t len, devino *devino, unsigned int options)
+{
+ int fd = openc_trunc(fn) ;
+ if (fd < 0) return 0 ;
+ if (!writenclose_unsafe5(fd, s, len, devino, options))
+ {
+ fd_close(fd) ;
+ unlink_void(fn) ;
+ return 0 ;
+ }
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritenclose_unsafe_internal_deprecated.c b/src/libstddjb/openwritenclose_unsafe_internal_deprecated.c
new file mode 100644
index 0000000..58f88e6
--- /dev/null
+++ b/src/libstddjb/openwritenclose_unsafe_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+#include <skalibs/djbunix.h>
+
+int openwritenclose_unsafe_internal (char const *fn, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync)
+{
+ devino di ;
+ if (!openwritenclose_unsafe5(fn, s, len, dev || ino ? &di : 0, !!dosync)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritevnclose.c b/src/libstddjb/openwritevnclose5.c
index 01df3e3..6465c4d 100644
--- a/src/libstddjb/openwritevnclose.c
+++ b/src/libstddjb/openwritevnclose5.c
@@ -1,39 +1,30 @@
/* ISC license. */
-#include <sys/uio.h>
#include <string.h>
-#include <errno.h>
-#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
+
+#include <skalibs/posixplz.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)
+int openwritevnclose5 (char const *fn, struct iovec const *v, unsigned int vlen, devino *devino, unsigned int options)
{
- dev_t tmpdev ;
- ino_t tmpino ;
- size_t fnlen = strlen(fn) ;
int fd ;
+ size_t fnlen = strlen(fn) ;
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 (!writevnclose_unsafe5(fd, v, vlen, devino, options)) 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 ;
- }
+ unlink_void(tmp) ;
return 0 ;
}
diff --git a/src/libstddjb/openwritevnclose_internal_deprecated.c b/src/libstddjb/openwritevnclose_internal_deprecated.c
new file mode 100644
index 0000000..1e0bfd1
--- /dev/null
+++ b/src/libstddjb/openwritevnclose_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+#include <skalibs/djbunix.h>
+
+int openwritevnclose_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync)
+{
+ devino di ;
+ if (!openwritevnclose5(fn, v, vlen, dev || ino ? &di : 0, !!dosync)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritevnclose_suffix.c b/src/libstddjb/openwritevnclose_suffix.c
deleted file mode 100644
index 2085fd3..0000000
--- a/src/libstddjb/openwritevnclose_suffix.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/* ISC license. */
-
-#include <sys/uio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <skalibs/djbunix.h>
-
-int openwritevnclose_suffix_internal (char const *fn, struct iovec const *v, unsigned int n, dev_t *dev, ino_t *ino, int dosync, char const *suffix)
-{
- dev_t tmpdev ;
- ino_t tmpino ;
- size_t len = strlen(fn) ;
- size_t suffixlen = strlen(suffix) ;
- char tmp[len + suffixlen + 1] ;
- memcpy(tmp, fn, len) ;
- memcpy(tmp + len, suffix, suffixlen + 1) ;
- if (!openwritevnclose_unsafe_internal(tmp, v, n, dev ? &tmpdev : 0, ino ? &tmpino : 0, dosync)) return 0 ;
- if (rename(tmp, fn) < 0)
- {
- int e = errno ;
- unlink(tmp) ;
- errno = e ;
- return 0 ;
- }
- if (dev) *dev = tmpdev ;
- if (ino) *ino = tmpino ;
- return 1 ;
-}
diff --git a/src/libstddjb/openwritevnclose_suffix6.c b/src/libstddjb/openwritevnclose_suffix6.c
new file mode 100644
index 0000000..3a9af3d
--- /dev/null
+++ b/src/libstddjb/openwritevnclose_suffix6.c
@@ -0,0 +1,23 @@
+/* ISC license. */
+
+#include <string.h>
+#include <stdio.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/djbunix.h>
+
+int openwritevnclose_suffix6 (char const *fn, struct iovec const *v, unsigned int n, devino *devino, unsigned int options, char const *suffix)
+{
+ size_t len = strlen(fn) ;
+ size_t suffixlen = strlen(suffix) ;
+ char tmp[len + suffixlen + 1] ;
+ memcpy(tmp, fn, len) ;
+ memcpy(tmp + len, suffix, suffixlen + 1) ;
+ if (!openwritevnclose_unsafe5(tmp, v, n, devino, options)) return 0 ;
+ if (rename(tmp, fn) < 0)
+ {
+ unlink_void(tmp) ;
+ return 0 ;
+ }
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritevnclose_suffix_internal_deprecated.c b/src/libstddjb/openwritevnclose_suffix_internal_deprecated.c
new file mode 100644
index 0000000..47278e5
--- /dev/null
+++ b/src/libstddjb/openwritevnclose_suffix_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+#include <skalibs/djbunix.h>
+
+int openwritevnclose_suffix_internal (char const *fn, struct iovec const *v, unsigned int n, dev_t *dev, ino_t *ino, int dosync, char const *suffix)
+{
+ devino di ;
+ if (!openwritevnclose_suffix6(fn, v, n, dev || ino ? &di : 0, !!dosync, suffix)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritevnclose_unsafe.c b/src/libstddjb/openwritevnclose_unsafe.c
deleted file mode 100644
index ca98f1c..0000000
--- a/src/libstddjb/openwritevnclose_unsafe.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ISC license. */
-
-#include <sys/uio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <skalibs/allreadwrite.h>
-#include <skalibs/djbunix.h>
-
-int openwritevnclose_unsafe_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync)
-{
- int fd = openc_trunc(fn) ;
- if (fd < 0) return 0 ;
- if (!writevnclose_unsafe_internal(fd, v, vlen, dev, ino, dosync))
- {
- int e = errno ;
- fd_close(fd) ;
- unlink(fn) ;
- errno = e ;
- return 0 ;
- }
- return 1 ;
-}
diff --git a/src/libstddjb/openwritevnclose_unsafe5.c b/src/libstddjb/openwritevnclose_unsafe5.c
new file mode 100644
index 0000000..db82f72
--- /dev/null
+++ b/src/libstddjb/openwritevnclose_unsafe5.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <skalibs/posixplz.h>
+#include <skalibs/djbunix.h>
+
+int openwritevnclose_unsafe5 (char const *fn, struct iovec const *v, unsigned int vlen, devino *devino, unsigned int options)
+{
+ int fd = openc_trunc(fn) ;
+ if (fd < 0) return 0 ;
+ if (!writevnclose_unsafe5(fd, v, vlen, devino, options))
+ {
+ fd_close(fd) ;
+ unlink_void(fn) ;
+ return 0 ;
+ }
+ return 1 ;
+}
diff --git a/src/libstddjb/openwritevnclose_unsafe_internal_deprecated.c b/src/libstddjb/openwritevnclose_unsafe_internal_deprecated.c
new file mode 100644
index 0000000..b81881d
--- /dev/null
+++ b/src/libstddjb/openwritevnclose_unsafe_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+#include <skalibs/djbunix.h>
+
+int openwritevnclose_unsafe_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync)
+{
+ devino di ;
+ if (!openwritevnclose_unsafe5(fn, v, vlen, dev || ino ? &di : 0, !!dosync)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}
diff --git a/src/libstddjb/writenclose_unsafe.c b/src/libstddjb/writenclose_unsafe.c
deleted file mode 100644
index f71caea..0000000
--- a/src/libstddjb/writenclose_unsafe.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* ISC license. */
-
-#include <sys/stat.h>
-#include <errno.h>
-#include <skalibs/allreadwrite.h>
-#include <skalibs/djbunix.h>
-
-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 ;
-}
diff --git a/src/libstddjb/writenclose_unsafe5.c b/src/libstddjb/writenclose_unsafe5.c
new file mode 100644
index 0000000..b0cbe48
--- /dev/null
+++ b/src/libstddjb/writenclose_unsafe5.c
@@ -0,0 +1,22 @@
+/* ISC license. */
+
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <skalibs/allreadwrite.h>
+#include <skalibs/djbunix.h>
+
+int writenclose_unsafe5 (int fd, char const *s, size_t len, devino *devino, unsigned int options)
+{
+ if (allwrite(fd, s, len) < len) return 0 ;
+ if (options & 1 && fd_sync(fd) == -1 && errno != EINVAL) return 0 ;
+ if (devino)
+ {
+ struct stat st ;
+ if (fstat(fd, &st) == -1) return 0 ;
+ devino->dev = st.st_dev ;
+ devino->ino = st.st_ino ;
+ }
+ fd_close(fd) ;
+ return 1 ;
+}
diff --git a/src/libstddjb/writenclose_unsafe_internal_deprecated.c b/src/libstddjb/writenclose_unsafe_internal_deprecated.c
new file mode 100644
index 0000000..d5ba77c
--- /dev/null
+++ b/src/libstddjb/writenclose_unsafe_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.h>
+#include <skalibs/djbunix.h>
+
+int writenclose_unsafe_internal (int fd, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync)
+{
+ devino di ;
+ if (!writenclose_unsafe5(fd, s, len, dev || ino ? &di : 0, !!dosync)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}
diff --git a/src/libstddjb/writevnclose_unsafe.c b/src/libstddjb/writevnclose_unsafe.c
deleted file mode 100644
index 9d2348a..0000000
--- a/src/libstddjb/writevnclose_unsafe.c
+++ /dev/null
@@ -1,20 +0,0 @@
-/* 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 ;
-}
diff --git a/src/libstddjb/writevnclose_unsafe5.c b/src/libstddjb/writevnclose_unsafe5.c
new file mode 100644
index 0000000..49b1444
--- /dev/null
+++ b/src/libstddjb/writevnclose_unsafe5.c
@@ -0,0 +1,23 @@
+/* ISC license. */
+
+#include <sys/stat.h>
+#include <errno.h>
+
+#include <skalibs/allreadwrite.h>
+#include <skalibs/siovec.h>
+#include <skalibs/djbunix.h>
+
+int writevnclose_unsafe5 (int fd, struct iovec const *v, unsigned int vlen, devino *devino, unsigned int options)
+{
+ if (allwritev(fd, v, vlen) < siovec_len(v, vlen)) return 0 ;
+ if (options & 1 && fd_sync(fd) == -1 && errno != EINVAL) return 0 ;
+ if (devino)
+ {
+ struct stat st ;
+ if (fstat(fd, &st) == -1) return 0 ;
+ devino->dev = st.st_dev ;
+ devino->ino = st.st_ino ;
+ }
+ fd_close(fd) ;
+ return 1 ;
+}
diff --git a/src/libstddjb/writevnclose_unsafe_internal_deprecated.c b/src/libstddjb/writevnclose_unsafe_internal_deprecated.c
new file mode 100644
index 0000000..d966500
--- /dev/null
+++ b/src/libstddjb/writevnclose_unsafe_internal_deprecated.c
@@ -0,0 +1,13 @@
+/* ISC license. */
+
+#include <skalibs/devino.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)
+{
+ devino di ;
+ if (!writevnclose_unsafe5(fd, v, vlen, dev || ino ? &di : 0, !!dosync)) return 0 ;
+ if (dev) *dev = di.dev ;
+ if (ino) *ino = di.ino ;
+ return 1 ;
+}