From c005b541bf9d54327ff860aad88367b854bae3d8 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 9 Jun 2023 13:32:27 +0000 Subject: Add devino, refactor openwrite(v)nclose Signed-off-by: Laurent Bercot --- src/libstddjb/devino_cmp.c | 13 ++++++++ src/libstddjb/openwritenclose.c | 38 --------------------- src/libstddjb/openwritenclose5.c | 31 +++++++++++++++++ .../openwritenclose_internal_deprecated.c | 13 ++++++++ src/libstddjb/openwritenclose_suffix.c | 29 ---------------- src/libstddjb/openwritenclose_suffix6.c | 23 +++++++++++++ .../openwritenclose_suffix_internal_deprecated.c | 13 ++++++++ src/libstddjb/openwritenclose_unsafe.c | 20 ----------- src/libstddjb/openwritenclose_unsafe5.c | 20 +++++++++++ .../openwritenclose_unsafe_internal_deprecated.c | 13 ++++++++ src/libstddjb/openwritevnclose.c | 39 ---------------------- src/libstddjb/openwritevnclose5.c | 30 +++++++++++++++++ .../openwritevnclose_internal_deprecated.c | 13 ++++++++ src/libstddjb/openwritevnclose_suffix.c | 30 ----------------- src/libstddjb/openwritevnclose_suffix6.c | 23 +++++++++++++ .../openwritevnclose_suffix_internal_deprecated.c | 13 ++++++++ src/libstddjb/openwritevnclose_unsafe.c | 22 ------------ src/libstddjb/openwritevnclose_unsafe5.c | 17 ++++++++++ .../openwritevnclose_unsafe_internal_deprecated.c | 13 ++++++++ src/libstddjb/writenclose_unsafe.c | 18 ---------- src/libstddjb/writenclose_unsafe5.c | 22 ++++++++++++ .../writenclose_unsafe_internal_deprecated.c | 13 ++++++++ src/libstddjb/writevnclose_unsafe.c | 20 ----------- src/libstddjb/writevnclose_unsafe5.c | 23 +++++++++++++ .../writevnclose_unsafe_internal_deprecated.c | 13 ++++++++ 25 files changed, 306 insertions(+), 216 deletions(-) create mode 100644 src/libstddjb/devino_cmp.c delete mode 100644 src/libstddjb/openwritenclose.c create mode 100644 src/libstddjb/openwritenclose5.c create mode 100644 src/libstddjb/openwritenclose_internal_deprecated.c delete mode 100644 src/libstddjb/openwritenclose_suffix.c create mode 100644 src/libstddjb/openwritenclose_suffix6.c create mode 100644 src/libstddjb/openwritenclose_suffix_internal_deprecated.c delete mode 100644 src/libstddjb/openwritenclose_unsafe.c create mode 100644 src/libstddjb/openwritenclose_unsafe5.c create mode 100644 src/libstddjb/openwritenclose_unsafe_internal_deprecated.c delete mode 100644 src/libstddjb/openwritevnclose.c create mode 100644 src/libstddjb/openwritevnclose5.c create mode 100644 src/libstddjb/openwritevnclose_internal_deprecated.c delete mode 100644 src/libstddjb/openwritevnclose_suffix.c create mode 100644 src/libstddjb/openwritevnclose_suffix6.c create mode 100644 src/libstddjb/openwritevnclose_suffix_internal_deprecated.c delete mode 100644 src/libstddjb/openwritevnclose_unsafe.c create mode 100644 src/libstddjb/openwritevnclose_unsafe5.c create mode 100644 src/libstddjb/openwritevnclose_unsafe_internal_deprecated.c delete mode 100644 src/libstddjb/writenclose_unsafe.c create mode 100644 src/libstddjb/writenclose_unsafe5.c create mode 100644 src/libstddjb/writenclose_unsafe_internal_deprecated.c delete mode 100644 src/libstddjb/writevnclose_unsafe.c create mode 100644 src/libstddjb/writevnclose_unsafe5.c create mode 100644 src/libstddjb/writevnclose_unsafe_internal_deprecated.c (limited to 'src/libstddjb') 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 + +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/openwritenclose.c deleted file mode 100644 index 427e53e..0000000 --- a/src/libstddjb/openwritenclose.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include -#include - -#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) -{ - dev_t tmpdev ; - ino_t tmpino ; - size_t fnlen = strlen(fn) ; - int fd ; - 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 (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 ; - } - return 0 ; -} diff --git a/src/libstddjb/openwritenclose5.c b/src/libstddjb/openwritenclose5.c new file mode 100644 index 0000000..eef625c --- /dev/null +++ b/src/libstddjb/openwritenclose5.c @@ -0,0 +1,31 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include + +#define SUFFIX ":skalibs-openwritenclose:XXXXXX" + +int openwritenclose5 (char const *fn, char const *s, size_t n, devino *devino, unsigned int options) +{ + 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_unsafe5(fd, s, n, devino, options)) goto failclose ; + if (rename(tmp, fn) < 0) goto fail ; + return 1 ; + + failclose: + fd_close(fd) ; + fail: + 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 +#include + +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 -#include -#include -#include -#include - -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 +#include + +#include +#include + +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 +#include + +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 -#include -#include - -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 +#include + +#include +#include + +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 +#include + +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/openwritevnclose.c deleted file mode 100644 index 01df3e3..0000000 --- a/src/libstddjb/openwritevnclose.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ISC license. */ - -#include -#include -#include -#include -#include -#include -#include - -#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) -{ - dev_t tmpdev ; - ino_t tmpino ; - size_t fnlen = strlen(fn) ; - int fd ; - 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 (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 ; - } - return 0 ; -} diff --git a/src/libstddjb/openwritevnclose5.c b/src/libstddjb/openwritevnclose5.c new file mode 100644 index 0000000..6465c4d --- /dev/null +++ b/src/libstddjb/openwritevnclose5.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include + +#define SUFFIX ":skalibs-openwritevnclose:XXXXXX" + +int openwritevnclose5 (char const *fn, struct iovec const *v, unsigned int vlen, devino *devino, unsigned int options) +{ + 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_unsafe5(fd, v, vlen, devino, options)) goto failclose ; + if (rename(tmp, fn) < 0) goto fail ; + return 1 ; + + failclose: + fd_close(fd) ; + fail: + 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 +#include + +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 -#include -#include -#include -#include -#include - -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 +#include + +#include +#include + +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 +#include + +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 -#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) -{ - 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 +#include + +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 +#include + +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 -#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 ; -} 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 +#include + +#include +#include + +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 +#include + +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 -#include -#include -#include -#include -#include - -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 +#include + +#include +#include +#include + +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 +#include + +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 ; +} -- cgit v1.2.3