diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2022-05-30 19:51:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2022-05-30 19:51:44 +0000 |
commit | 37b42c179bb00d05cb47c739cb95283548f84fb2 (patch) | |
tree | b73d99a6bb423c9f014b7049a01b2297feaf6221 | |
parent | 7d0199963a2ec019270ee187f8c9cb8adb25dac1 (diff) | |
download | skalibs-37b42c179bb00d05cb47c739cb95283548f84fb2.tar.gz skalibs-37b42c179bb00d05cb47c739cb95283548f84fb2.tar.xz skalibs-37b42c179bb00d05cb47c739cb95283548f84fb2.zip |
Add openc_*at functions
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | AUTHORS | 2 | ||||
-rw-r--r-- | package/deps.mak | 12 | ||||
-rw-r--r-- | src/include/skalibs/unix-transactional.h | 22 | ||||
-rw-r--r-- | src/libunixonacid/access_at.c | 2 | ||||
-rw-r--r-- | src/libunixonacid/openc_appendat.c | 11 | ||||
-rw-r--r-- | src/libunixonacid/openc_appendatb.c | 12 | ||||
-rw-r--r-- | src/libunixonacid/openc_readat.c | 10 | ||||
-rw-r--r-- | src/libunixonacid/openc_readatb.c | 12 | ||||
-rw-r--r-- | src/libunixonacid/openc_truncat.c | 10 | ||||
-rw-r--r-- | src/libunixonacid/openc_truncatb.c | 12 | ||||
-rw-r--r-- | src/libunixonacid/openc_writeat.c | 10 | ||||
-rw-r--r-- | src/libunixonacid/openc_writeatb.c | 12 | ||||
-rw-r--r-- | src/libunixonacid/opendir_at.c | 6 | ||||
-rw-r--r-- | src/libunixonacid/opengetlnclose.c | 2 | ||||
-rw-r--r-- | src/libunixonacid/opengetlnclose_at.c | 2 | ||||
-rw-r--r-- | src/libunixonacid/openreadnclose_at.c | 3 | ||||
-rw-r--r-- | src/libunixonacid/openslurpclose_at.c | 2 | ||||
-rw-r--r-- | src/libunixonacid/openwritenclose_at.c | 3 | ||||
-rw-r--r-- | src/libunixonacid/openwritevnclose_at.c | 3 |
19 files changed, 130 insertions, 18 deletions
diff --git a/AUTHORS b/AUTHORS index da242b2..e3a8a11 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,3 +42,5 @@ Thanks to: Josuah Demangeon <me@josuah.net> Xavier Stonestreet <xstonestreet@gmail.com> Jason Donenfeld <jason@zx2c4.com> + Amitai Schleier <schmonz@schmonz.com> + psykose <alice@ayaya.dev> diff --git a/package/deps.mak b/package/deps.mak index c9db09f..6210f29 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -51,7 +51,7 @@ src/include/skalibs/tai.h: src/include/skalibs/gccattributes.h src/include/skali src/include/skalibs/textclient.h: src/include/skalibs/allreadwrite.h src/include/skalibs/tai.h src/include/skalibs/textmessage.h src/include/skalibs/textmessage.h: src/include/skalibs/allreadwrite.h src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/gccattributes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unix-timed.h: src/include/skalibs/bufalloc.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h -src/include/skalibs/unix-transactional.h: src/include/skalibs/direntry.h src/include/skalibs/stralloc.h src/include/skalibs/uint64.h +src/include/skalibs/unix-transactional.h: src/include/skalibs/direntry.h src/include/skalibs/stralloc.h src/include/skalibs/unixconnection.h: src/include/skalibs/unixmessage.h src/include/skalibs/unixmessage.h: src/include/skalibs/buffer.h src/include/skalibs/cbuffer.h src/include/skalibs/gccattributes.h src/include/skalibs/genalloc.h src/include/skalibs/stralloc.h src/include/skalibs/tai.h src/include/skalibs/unixonacid.h: src/include/skalibs/ancil.h src/include/skalibs/kolbak.h src/include/skalibs/skaclient.h src/include/skalibs/textclient.h src/include/skalibs/textmessage.h src/include/skalibs/unix-timed.h src/include/skalibs/unix-transactional.h src/include/skalibs/unixconnection.h src/include/skalibs/unixmessage.h @@ -716,7 +716,15 @@ src/libunixonacid/open_truncat.o src/libunixonacid/open_truncat.lo: src/libunixo src/libunixonacid/open_truncatb.o src/libunixonacid/open_truncatb.lo: src/libunixonacid/open_truncatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h src/libunixonacid/open_writeat.o src/libunixonacid/open_writeat.lo: src/libunixonacid/open_writeat.c src/include/skalibs/unix-transactional.h src/libunixonacid/open_writeatb.o src/libunixonacid/open_writeatb.lo: src/libunixonacid/open_writeatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h -src/libunixonacid/opendir_at.o src/libunixonacid/opendir_at.lo: src/libunixonacid/opendir_at.c src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_appendat.o src/libunixonacid/openc_appendat.lo: src/libunixonacid/openc_appendat.c src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_appendatb.o src/libunixonacid/openc_appendatb.lo: src/libunixonacid/openc_appendatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_readat.o src/libunixonacid/openc_readat.lo: src/libunixonacid/openc_readat.c src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_readatb.o src/libunixonacid/openc_readatb.lo: src/libunixonacid/openc_readatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_truncat.o src/libunixonacid/openc_truncat.lo: src/libunixonacid/openc_truncat.c src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_truncatb.o src/libunixonacid/openc_truncatb.lo: src/libunixonacid/openc_truncatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_writeat.o src/libunixonacid/openc_writeat.lo: src/libunixonacid/openc_writeat.c src/include/skalibs/unix-transactional.h +src/libunixonacid/openc_writeatb.o src/libunixonacid/openc_writeatb.lo: src/libunixonacid/openc_writeatb.c src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h +src/libunixonacid/opendir_at.o src/libunixonacid/opendir_at.lo: src/libunixonacid/opendir_at.c src/include/skalibs/direntry.h src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/unix-transactional.h src/libunixonacid/opengetlnclose.o src/libunixonacid/opengetlnclose.lo: src/libunixonacid/opengetlnclose.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h src/libunixonacid/opengetlnclose_at.o src/libunixonacid/opengetlnclose_at.lo: src/libunixonacid/opengetlnclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/djbunix.h src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h src/libunixonacid/openreadnclose_at.o src/libunixonacid/openreadnclose_at.lo: src/libunixonacid/openreadnclose_at.c src/include/skalibs/allreadwrite.h src/include/skalibs/djbunix.h src/include/skalibs/unix-transactional.h diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h index 88d1838..5b9c4fa 100644 --- a/src/include/skalibs/unix-transactional.h +++ b/src/include/skalibs/unix-transactional.h @@ -3,21 +3,23 @@ #ifndef SKALIBS_UNIX_TRANSACTIONAL_H #define SKALIBS_UNIX_TRANSACTIONAL_H -#include <sys/types.h> +#include <stddef.h> #include <sys/stat.h> #include <sys/uio.h> -#include <skalibs/uint64.h> #include <skalibs/direntry.h> #include <skalibs/stralloc.h> /* Transactional/reliable filesystem operations */ +extern int opengetlnclose (char const *, stralloc *, int) ; + extern int open2_at (int, char const *, int) ; extern int open3_at (int, char const *, int, unsigned int) ; extern int access_at (int, char const *, int, unsigned int) ; - -extern int opengetlnclose (char const *, stralloc *, int) ; +extern DIR *opendir_at (int, char const *) ; +extern int stat_at (int, char const *, struct stat *) ; +extern int lstat_at (int, char const *, struct stat *) ; extern int open_readat (int, char const *) ; extern int open_readatb (int, char const *) ; @@ -27,10 +29,14 @@ extern int open_truncat (int, char const *) ; extern int open_truncatb (int, char const *) ; extern int open_appendat (int, char const *) ; extern int open_appendatb (int, char const *) ; -extern DIR *opendir_at (int, char const *) ; - -extern int stat_at (int, char const *, struct stat *) ; -extern int lstat_at (int, char const *, struct stat *) ; +extern int openc_readat (int, char const *) ; +extern int openc_readatb (int, char const *) ; +extern int openc_writeat (int, char const *) ; +extern int openc_writeatb (int, char const *) ; +extern int openc_truncat (int, char const *) ; +extern int openc_truncatb (int, char const *) ; +extern int openc_appendat (int, char const *) ; +extern int openc_appendatb (int, char const *) ; extern size_t openreadnclose_at (int, char const *, char *, size_t) ; extern int openslurpclose_at (int, char const *, stralloc *) ; diff --git a/src/libunixonacid/access_at.c b/src/libunixonacid/access_at.c index ebe6dd7..69fdce4 100644 --- a/src/libunixonacid/access_at.c +++ b/src/libunixonacid/access_at.c @@ -34,7 +34,7 @@ int access_at (int dirfd, char const *file, int amode, unsigned int flag) if (getuid() != geteuid() || getgid() != getegid()) return (errno = ENOSYS, -1) ; (void)flag ; - fdhere = open_read(".") ; + fdhere = openc_read(".") ; if (fdhere < 0) return -1 ; if (fd_chdir(dirfd) < 0) { diff --git a/src/libunixonacid/openc_appendat.c b/src/libunixonacid/openc_appendat.c new file mode 100644 index 0000000..70b6df7 --- /dev/null +++ b/src/libunixonacid/openc_appendat.c @@ -0,0 +1,11 @@ +/* ISC license. */ + +#include <sys/stat.h> +#include <fcntl.h> + +#include <skalibs/unix-transactional.h> + +int openc_appendat (int fd, char const *name) +{ + return open3_at(fd, name, O_WRONLY | O_NONBLOCK | O_APPEND | O_CREAT | O_CLOEXEC, 0666) ; +} diff --git a/src/libunixonacid/openc_appendatb.c b/src/libunixonacid/openc_appendatb.c new file mode 100644 index 0000000..066e695 --- /dev/null +++ b/src/libunixonacid/openc_appendatb.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include <skalibs/djbunix.h> +#include <skalibs/unix-transactional.h> + +int openc_appendatb (int dirfd, char const *name) +{ + int fd = openc_appendat(dirfd, name) ; + if (fd < 0) return -1 ; + if (ndelay_off(fd) < 0) return -1 ; + return fd ; +} diff --git a/src/libunixonacid/openc_readat.c b/src/libunixonacid/openc_readat.c new file mode 100644 index 0000000..dc092b6 --- /dev/null +++ b/src/libunixonacid/openc_readat.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <fcntl.h> + +#include <skalibs/unix-transactional.h> + +int openc_readat (int fd, char const *name) +{ + return open2_at(fd, name, O_RDONLY | O_NONBLOCK | O_CLOEXEC) ; +} diff --git a/src/libunixonacid/openc_readatb.c b/src/libunixonacid/openc_readatb.c new file mode 100644 index 0000000..4da65ab --- /dev/null +++ b/src/libunixonacid/openc_readatb.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include <skalibs/djbunix.h> +#include <skalibs/unix-transactional.h> + +int openc_readatb (int dirfd, char const *name) +{ + int fd = openc_readat(dirfd, name) ; + if (fd < 0) return -1 ; + if (ndelay_off(fd) < 0) return -1 ; + return fd ; +} diff --git a/src/libunixonacid/openc_truncat.c b/src/libunixonacid/openc_truncat.c new file mode 100644 index 0000000..8ce50d2 --- /dev/null +++ b/src/libunixonacid/openc_truncat.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <fcntl.h> + +#include <skalibs/unix-transactional.h> + +int openc_truncat (int fd, char const *name) +{ + return open3_at(fd, name, O_WRONLY | O_NONBLOCK | O_TRUNC | O_CREAT | O_CLOEXEC, 0666) ; +} diff --git a/src/libunixonacid/openc_truncatb.c b/src/libunixonacid/openc_truncatb.c new file mode 100644 index 0000000..a791790 --- /dev/null +++ b/src/libunixonacid/openc_truncatb.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include <skalibs/djbunix.h> +#include <skalibs/unix-transactional.h> + +int openc_truncatb (int dirfd, char const *name) +{ + int fd = openc_truncat(dirfd, name) ; + if (fd < 0) return -1 ; + if (ndelay_off(fd) < 0) return -1 ; + return fd ; +} diff --git a/src/libunixonacid/openc_writeat.c b/src/libunixonacid/openc_writeat.c new file mode 100644 index 0000000..e584e57 --- /dev/null +++ b/src/libunixonacid/openc_writeat.c @@ -0,0 +1,10 @@ +/* ISC license. */ + +#include <fcntl.h> + +#include <skalibs/unix-transactional.h> + +int openc_writeat (int fd, char const *name) +{ + return open2_at(fd, name, O_WRONLY | O_NONBLOCK | O_CLOEXEC) ; +} diff --git a/src/libunixonacid/openc_writeatb.c b/src/libunixonacid/openc_writeatb.c new file mode 100644 index 0000000..daa1fe8 --- /dev/null +++ b/src/libunixonacid/openc_writeatb.c @@ -0,0 +1,12 @@ +/* ISC license. */ + +#include <skalibs/djbunix.h> +#include <skalibs/unix-transactional.h> + +int openc_writeatb (int dirfd, char const *name) +{ + int fd = openc_writeat(dirfd, name) ; + if (fd < 0) return -1 ; + if (ndelay_off(fd) < 0) return -1 ; + return fd ; +} diff --git a/src/libunixonacid/opendir_at.c b/src/libunixonacid/opendir_at.c index bee971f..c1de4f1 100644 --- a/src/libunixonacid/opendir_at.c +++ b/src/libunixonacid/opendir_at.c @@ -1,5 +1,9 @@ /* ISC license. */ +/* Should not be necessary but old NetBSD/OpenBSD fail to + properly expose fdopendir() otherwise */ +#include <skalibs/nonposix.h> + #include <skalibs/direntry.h> #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> @@ -7,7 +11,7 @@ DIR *opendir_at (int dfd, char const *name) { DIR *dir ; - int fd = open_readatb(dfd, name) ; + int fd = openc_readatb(dfd, name) ; if (fd < 0) return 0 ; dir = fdopendir(fd) ; if (!dir) fd_close(fd) ; diff --git a/src/libunixonacid/opengetlnclose.c b/src/libunixonacid/opengetlnclose.c index 8c6e076..4840713 100644 --- a/src/libunixonacid/opengetlnclose.c +++ b/src/libunixonacid/opengetlnclose.c @@ -11,7 +11,7 @@ int opengetlnclose (char const *fn, stralloc *sa, int sep) char buf[BUFFER_INSIZE] ; buffer b ; int r ; - int fd = open_readb(fn) ; + int fd = openc_readb(fn) ; if (fd < 0) return -1 ; buffer_init(&b, &fd_readv, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; diff --git a/src/libunixonacid/opengetlnclose_at.c b/src/libunixonacid/opengetlnclose_at.c index cc2f86a..ff500e7 100644 --- a/src/libunixonacid/opengetlnclose_at.c +++ b/src/libunixonacid/opengetlnclose_at.c @@ -11,7 +11,7 @@ int opengetlnclose_at (int dirfd, char const *fn, stralloc *sa, int sep) char buf[BUFFER_INSIZE] ; buffer b ; int r ; - int fd = open_readatb(dirfd, fn) ; + int fd = openc_readatb(dirfd, fn) ; if (fd < 0) return -1 ; buffer_init(&b, &buffer_read, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; diff --git a/src/libunixonacid/openreadnclose_at.c b/src/libunixonacid/openreadnclose_at.c index e03c04b..8100997 100644 --- a/src/libunixonacid/openreadnclose_at.c +++ b/src/libunixonacid/openreadnclose_at.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <errno.h> + #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> @@ -9,7 +10,7 @@ size_t openreadnclose_at (int dirfd, char const *file, char *s, size_t n) { size_t r ; int e ; - int fd = open_readatb(dirfd, file) ; + int fd = openc_readatb(dirfd, file) ; if (fd < 0) return 0 ; r = allread(fd, s, n) ; e = errno ; diff --git a/src/libunixonacid/openslurpclose_at.c b/src/libunixonacid/openslurpclose_at.c index bf6d3ab..4ab6fa5 100644 --- a/src/libunixonacid/openslurpclose_at.c +++ b/src/libunixonacid/openslurpclose_at.c @@ -5,7 +5,7 @@ int openslurpclose_at (int dirfd, char const *fn, stralloc *sa) { - int fd = open_readatb(dirfd, fn) ; + int fd = openc_readatb(dirfd, fn) ; if (fd < 0) return 0 ; if (!slurp(sa, fd)) { diff --git a/src/libunixonacid/openwritenclose_at.c b/src/libunixonacid/openwritenclose_at.c index 015c0c8..c901952 100644 --- a/src/libunixonacid/openwritenclose_at.c +++ b/src/libunixonacid/openwritenclose_at.c @@ -1,6 +1,7 @@ /* ISC license. */ #include <unistd.h> + #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> @@ -8,7 +9,7 @@ size_t openwritenclose_at (int dirfd, char const *file, char const *s, size_t n) { size_t r ; - int fd = open_truncatb(dirfd, file) ; + int fd = openc_truncatb(dirfd, file) ; if (fd < 0) return 0 ; r = allwrite(fd, s, n) ; if (r >= n) fsync(fd) ; diff --git a/src/libunixonacid/openwritevnclose_at.c b/src/libunixonacid/openwritevnclose_at.c index ba1e789..5fcdc0b 100644 --- a/src/libunixonacid/openwritevnclose_at.c +++ b/src/libunixonacid/openwritevnclose_at.c @@ -2,6 +2,7 @@ #include <sys/uio.h> #include <unistd.h> + #include <skalibs/allreadwrite.h> #include <skalibs/siovec.h> #include <skalibs/djbunix.h> @@ -10,7 +11,7 @@ size_t openwritevnclose_at (int dirfd, char const *file, struct iovec const *v, unsigned int n) { size_t r ; - int fd = open_truncatb(dirfd, file) ; + int fd = openc_truncatb(dirfd, file) ; if (fd < 0) return 0 ; r = allwritev(fd, v, n) ; if (r >= siovec_len(v, n)) fsync(fd) ; |