summaryrefslogtreecommitdiff
path: root/src/libunixonacid
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-05-30 19:51:44 +0000
committerLaurent Bercot <ska@appnovation.com>2022-05-30 19:51:44 +0000
commit37b42c179bb00d05cb47c739cb95283548f84fb2 (patch)
treeb73d99a6bb423c9f014b7049a01b2297feaf6221 /src/libunixonacid
parent7d0199963a2ec019270ee187f8c9cb8adb25dac1 (diff)
downloadskalibs-37b42c179bb00d05cb47c739cb95283548f84fb2.tar.xz
Add openc_*at functions
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libunixonacid')
-rw-r--r--src/libunixonacid/access_at.c2
-rw-r--r--src/libunixonacid/openc_appendat.c11
-rw-r--r--src/libunixonacid/openc_appendatb.c12
-rw-r--r--src/libunixonacid/openc_readat.c10
-rw-r--r--src/libunixonacid/openc_readatb.c12
-rw-r--r--src/libunixonacid/openc_truncat.c10
-rw-r--r--src/libunixonacid/openc_truncatb.c12
-rw-r--r--src/libunixonacid/openc_writeat.c10
-rw-r--r--src/libunixonacid/openc_writeatb.c12
-rw-r--r--src/libunixonacid/opendir_at.c6
-rw-r--r--src/libunixonacid/opengetlnclose.c2
-rw-r--r--src/libunixonacid/opengetlnclose_at.c2
-rw-r--r--src/libunixonacid/openreadnclose_at.c3
-rw-r--r--src/libunixonacid/openslurpclose_at.c2
-rw-r--r--src/libunixonacid/openwritenclose_at.c3
-rw-r--r--src/libunixonacid/openwritevnclose_at.c3
16 files changed, 104 insertions, 8 deletions
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) ;