commit c005b541bf9d54327ff860aad88367b854bae3d8 parent 4af2899ac7ed0da49db7a6e94914fee391212f92 Author: Laurent Bercot <ska-skaware@skarnet.org> Date: Fri, 9 Jun 2023 13:32:27 +0000 Add devino, refactor openwrite(v)nclose Signed-off-by: Laurent Bercot <ska@appnovation.com> Diffstat:
30 files changed, 384 insertions(+), 254 deletions(-)
diff --git a/Makefile b/Makefile @@ -7,14 +7,17 @@ it: all +$(shell test -r config.mak) +ifneq ($(.SHELLSTATUS),0) +$(error Missing config.mak; please use ./configure first) +endif + make_need := 3.81 ifeq "" "$(strip $(filter $(make_need), $(firstword $(sort $(make_need) $(MAKE_VERSION)))))" -fail := $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer) +$(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer) endif -CC = $(error Please use ./configure first) - --include config.mak +include config.mak include package/deps.mak version_m := $(basename $(version)) diff --git a/package/deps.mak b/package/deps.mak @@ -18,7 +18,7 @@ src/include/skalibs/cdb.h: src/include/skalibs/gccattributes.h src/include/skalibs/cdbmake.h: src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/diuint32.h src/include/skalibs/genalloc.h src/include/skalibs/datastruct.h: src/include/skalibs/avlnode.h src/include/skalibs/avltree.h src/include/skalibs/avltreen.h src/include/skalibs/bigkv.h src/include/skalibs/genqdyn.h src/include/skalibs/genset.h src/include/skalibs/gensetdyn.h src/include/skalibs/djbtime.h: src/include/skalibs/tai.h src/include/skalibs/uint64.h -src/include/skalibs/djbunix.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h +src/include/skalibs/djbunix.h: src/include/skalibs/devino.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/env.h: src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/envalloc.h: src/include/skalibs/genalloc.h src/include/skalibs/error.h: src/include/skalibs/gccattributes.h @@ -44,7 +44,7 @@ src/include/skalibs/skalibs.h: src/include/skalibs/datastruct.h src/include/skal src/include/skalibs/skamisc.h: src/include/skalibs/buffer.h src/include/skalibs/stralloc.h src/include/skalibs/socket.h: src/include/skalibs/gccattributes.h src/include/skalibs/posixplz.h src/include/skalibs/tai.h src/include/skalibs/stdcrypto.h: src/include/skalibs/blake2s.h src/include/skalibs/sha1.h src/include/skalibs/sha256.h src/include/skalibs/sha512.h -src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdbmake.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/error.h src/include/skalibs/exec.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/netstring.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/types.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h +src/include/skalibs/stddjb.h: src/include/skalibs/alarm.h src/include/skalibs/alloc.h src/include/skalibs/allreadwrite.h src/include/skalibs/bitarray.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/bytestr.h src/include/skalibs/cbuffer.h src/include/skalibs/cdb.h src/include/skalibs/cdbmake.h src/include/skalibs/devino.h src/include/skalibs/direntry.h src/include/skalibs/disize.h src/include/skalibs/diuint.h src/include/skalibs/diuint32.h src/include/skalibs/djbtime.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/envalloc.h src/include/skalibs/error.h src/include/skalibs/exec.h src/include/skalibs/fmtscan.h src/include/skalibs/functypes.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/genwrite.h src/include/skalibs/iopause.h src/include/skalibs/ip46.h src/include/skalibs/lolstdio.h src/include/skalibs/netstring.h src/include/skalibs/segfault.h src/include/skalibs/selfpipe.h src/include/skalibs/setgroups.h src/include/skalibs/sgetopt.h src/include/skalibs/sig.h src/include/skalibs/siovec.h src/include/skalibs/skamisc.h src/include/skalibs/socket.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/types.h src/include/skalibs/uint16.h src/include/skalibs/uint32.h src/include/skalibs/uint64.h src/include/skalibs/strerr.h: src/include/skalibs/gccattributes.h src/include/skalibs/strerr2.h: src/include/skalibs/strerr.h src/include/skalibs/tai.h: src/include/skalibs/gccattributes.h src/include/skalibs/uint64.h @@ -302,6 +302,7 @@ src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_ src/libstddjb/child_spawn3.o src/libstddjb/child_spawn3.lo: src/libstddjb/child_spawn3.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/exec.h src/include/skalibs/sig.h src/include/skalibs/strerr.h src/include/skalibs/sysdeps.h src/include/skalibs/types.h src/libstddjb/coe.o src/libstddjb/coe.lo: src/libstddjb/coe.c src/include/skalibs/djbunix.h src/libstddjb/deepsleepuntil.o src/libstddjb/deepsleepuntil.lo: src/libstddjb/deepsleepuntil.c src/include/skalibs/iopause.h src/include/skalibs/tai.h +src/libstddjb/devino_cmp.o src/libstddjb/devino_cmp.lo: src/libstddjb/devino_cmp.c src/include/skalibs/devino.h src/libstddjb/dir_close.o src/libstddjb/dir_close.lo: src/libstddjb/dir_close.c src/include/skalibs/direntry.h src/libstddjb/dir_fd.o src/libstddjb/dir_fd.lo: src/libstddjb/dir_fd.c src/include/skalibs/direntry.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/error_isalready.o src/libstddjb/error_isalready.lo: src/libstddjb/error_isalready.c src/include/skalibs/bsdsnowflake.h src/include/skalibs/error.h @@ -443,12 +444,18 @@ src/libstddjb/openreadnclose.o src/libstddjb/openreadnclose.lo: src/libstddjb/op src/libstddjb/openreadnclose_nb.o src/libstddjb/openreadnclose_nb.lo: src/libstddjb/openreadnclose_nb.c src/include/skalibs/djbunix.h src/libstddjb/openslurpclose.o src/libstddjb/openslurpclose.lo: src/libstddjb/openslurpclose.c src/include/skalibs/djbunix.h src/libstddjb/openslurpnclose.o src/libstddjb/openslurpnclose.lo: src/libstddjb/openslurpnclose.c src/include/skalibs/djbunix.h -src/libstddjb/openwritenclose.o src/libstddjb/openwritenclose.lo: src/libstddjb/openwritenclose.c src/include/skalibs/djbunix.h -src/libstddjb/openwritenclose_suffix.o src/libstddjb/openwritenclose_suffix.lo: src/libstddjb/openwritenclose_suffix.c src/include/skalibs/djbunix.h -src/libstddjb/openwritenclose_unsafe.o src/libstddjb/openwritenclose_unsafe.lo: src/libstddjb/openwritenclose_unsafe.c src/include/skalibs/djbunix.h -src/libstddjb/openwritevnclose.o src/libstddjb/openwritevnclose.lo: src/libstddjb/openwritevnclose.c src/include/skalibs/djbunix.h -src/libstddjb/openwritevnclose_suffix.o src/libstddjb/openwritevnclose_suffix.lo: src/libstddjb/openwritevnclose_suffix.c src/include/skalibs/djbunix.h -src/libstddjb/openwritevnclose_unsafe.o src/libstddjb/openwritevnclose_unsafe.lo: src/libstddjb/openwritevnclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h +src/libstddjb/openwritenclose5.o src/libstddjb/openwritenclose5.lo: src/libstddjb/openwritenclose5.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h +src/libstddjb/openwritenclose_internal_deprecated.o src/libstddjb/openwritenclose_internal_deprecated.lo: src/libstddjb/openwritenclose_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h +src/libstddjb/openwritenclose_suffix6.o src/libstddjb/openwritenclose_suffix6.lo: src/libstddjb/openwritenclose_suffix6.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h +src/libstddjb/openwritenclose_suffix_internal_deprecated.o src/libstddjb/openwritenclose_suffix_internal_deprecated.lo: src/libstddjb/openwritenclose_suffix_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h +src/libstddjb/openwritenclose_unsafe5.o src/libstddjb/openwritenclose_unsafe5.lo: src/libstddjb/openwritenclose_unsafe5.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h +src/libstddjb/openwritenclose_unsafe_internal_deprecated.o src/libstddjb/openwritenclose_unsafe_internal_deprecated.lo: src/libstddjb/openwritenclose_unsafe_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h +src/libstddjb/openwritevnclose5.o src/libstddjb/openwritevnclose5.lo: src/libstddjb/openwritevnclose5.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h +src/libstddjb/openwritevnclose_internal_deprecated.o src/libstddjb/openwritevnclose_internal_deprecated.lo: src/libstddjb/openwritevnclose_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h +src/libstddjb/openwritevnclose_suffix6.o src/libstddjb/openwritevnclose_suffix6.lo: src/libstddjb/openwritevnclose_suffix6.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h +src/libstddjb/openwritevnclose_suffix_internal_deprecated.o src/libstddjb/openwritevnclose_suffix_internal_deprecated.lo: src/libstddjb/openwritevnclose_suffix_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h +src/libstddjb/openwritevnclose_unsafe5.o src/libstddjb/openwritevnclose_unsafe5.lo: src/libstddjb/openwritevnclose_unsafe5.c src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h +src/libstddjb/openwritevnclose_unsafe_internal_deprecated.o src/libstddjb/openwritevnclose_unsafe_internal_deprecated.lo: src/libstddjb/openwritevnclose_unsafe_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h src/libstddjb/path_canonicalize.o src/libstddjb/path_canonicalize.lo: src/libstddjb/path_canonicalize.c src/include/skalibs/djbunix.h src/libstddjb/pipe_internal.o src/libstddjb/pipe_internal.lo: src/libstddjb/pipe_internal.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/libstddjb/prog.o src/libstddjb/prog.lo: src/libstddjb/prog.c src/include/skalibs/strerr.h @@ -698,8 +705,10 @@ src/libstddjb/waitn_posix.o src/libstddjb/waitn_posix.lo: src/libstddjb/waitn_po src/libstddjb/waitn_reap.o src/libstddjb/waitn_reap.lo: src/libstddjb/waitn_reap.c src/include/skalibs/djbunix.h src/libstddjb/waitn_reap_posix.o src/libstddjb/waitn_reap_posix.lo: src/libstddjb/waitn_reap_posix.c src/include/skalibs/djbunix.h src/libstddjb/waitpid_nointr.o src/libstddjb/waitpid_nointr.lo: src/libstddjb/waitpid_nointr.c src/include/skalibs/djbunix.h -src/libstddjb/writenclose_unsafe.o src/libstddjb/writenclose_unsafe.lo: src/libstddjb/writenclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h -src/libstddjb/writevnclose_unsafe.o src/libstddjb/writevnclose_unsafe.lo: src/libstddjb/writevnclose_unsafe.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/siovec.h +src/libstddjb/writenclose_unsafe5.o src/libstddjb/writenclose_unsafe5.lo: src/libstddjb/writenclose_unsafe5.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h +src/libstddjb/writenclose_unsafe_internal_deprecated.o src/libstddjb/writenclose_unsafe_internal_deprecated.lo: src/libstddjb/writenclose_unsafe_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h +src/libstddjb/writevnclose_unsafe5.o src/libstddjb/writevnclose_unsafe5.lo: src/libstddjb/writevnclose_unsafe5.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/siovec.h +src/libstddjb/writevnclose_unsafe_internal_deprecated.o src/libstddjb/writevnclose_unsafe_internal_deprecated.lo: src/libstddjb/writevnclose_unsafe_internal_deprecated.c src/include/skalibs/devino.h src/include/skalibs/djbunix.h src/libunixonacid/access_at.o src/libunixonacid/access_at.lo: src/libunixonacid/access_at.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/unix-transactional.h src/libunixonacid/ancil_recv_fd.o src/libunixonacid/ancil_recv_fd.lo: src/libunixonacid/ancil_recv_fd.c src/include/skalibs/allreadwrite.h src/include/skalibs/ancil.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/sysdeps.h src/libunixonacid/ancil_send_fd.o src/libunixonacid/ancil_send_fd.lo: src/libunixonacid/ancil_send_fd.c src/include/skalibs/ancil.h src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h diff --git a/src/include/skalibs/devino.h 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 @@ -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 @@ -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 @@ -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/openwritenclose.c @@ -1,38 +0,0 @@ -/* ISC license. */ - -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.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) -{ - 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 @@ -0,0 +1,31 @@ +/* ISC license. */ + +#include <string.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 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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/openwritevnclose.c @@ -1,39 +0,0 @@ -/* ISC license. */ - -#include <sys/uio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.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) -{ - 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 @@ -0,0 +1,30 @@ +/* ISC license. */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include <skalibs/posixplz.h> +#include <skalibs/djbunix.h> + +#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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ; +}