From 9806a4f3bb81f71c46735a2b378cb074fef6e27b Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Mon, 26 Oct 2020 08:59:58 +0000
Subject: Prepare for 2.9.4.0; add open*coe() functions.
---
NEWS | 6 ++++
doc/index.html | 2 +-
doc/libstddjb/djbunix.html | 51 +++++++++++++++++++++++++++++++++
doc/license.html | 2 +-
doc/upgrade.html | 7 +++++
package/info | 2 +-
src/include/skalibs/djbunix.h | 8 ++++++
src/libstddjb/open_appendcoe.c | 10 +++++++
src/libstddjb/open_createcoe.c | 10 +++++++
src/libstddjb/open_exclcoe.c | 10 +++++++
src/libstddjb/open_readbcoe.c | 15 ++++++++++
src/libstddjb/open_readcoe.c | 10 +++++++
src/libstddjb/open_trunccoe.c | 10 +++++++
src/libstddjb/open_writecoe.c | 10 +++++++
src/libstddjb/openb_readcoe.c | 10 +++++++
src/libstddjb/openreadfileclose.c | 2 +-
src/libstddjb/openreadnclose.c | 4 +--
src/libstddjb/openslurpclose.c | 2 +-
src/libstddjb/openwritenclose_unsafe.c | 2 +-
src/libstddjb/openwritevnclose_unsafe.c | 2 +-
20 files changed, 166 insertions(+), 9 deletions(-)
create mode 100644 src/libstddjb/open_appendcoe.c
create mode 100644 src/libstddjb/open_createcoe.c
create mode 100644 src/libstddjb/open_exclcoe.c
create mode 100644 src/libstddjb/open_readbcoe.c
create mode 100644 src/libstddjb/open_readcoe.c
create mode 100644 src/libstddjb/open_trunccoe.c
create mode 100644 src/libstddjb/open_writecoe.c
create mode 100644 src/libstddjb/openb_readcoe.c
diff --git a/NEWS b/NEWS
index 887216d..becc140 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,11 @@
Changelog for skalibs.
+In 2.9.4.0
+----------
+
+ - New open*coe functions.
+
+
In 2.9.3.0
----------
diff --git a/doc/index.html b/doc/index.html
index 7d86278..c7cb59c 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -60,7 +60,7 @@ with a standard C development environment
Download
- - The current released version of skalibs is 2.9.3.0.
+ - The current released version of skalibs is 2.9.4.0.
- Alternatively, you can checkout a copy of the
skalibs
git repository:
diff --git a/doc/libstddjb/djbunix.html b/doc/libstddjb/djbunix.html
index 2e99dd0..0ac0a2c 100644
--- a/doc/libstddjb/djbunix.html
+++ b/doc/libstddjb/djbunix.html
@@ -253,12 +253,24 @@ Opens file in read-only, non-blocking mode.
Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+ int open_readcoe (char const *file)
+Opens file in read-only, non-blocking mode, close-on-exec.
+Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+
int openb_read (char const *file)
Opens file in read-only, blocking mode.
Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+ int openb_readcoe (char const *file)
+Opens file in read-only, blocking mode, close-on-exec.
+Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+
int open_readb (char const *file)
Opens file in read-only, blocking mode.
@@ -270,6 +282,11 @@ is set afterwards; this behaviour allows for more transparent interactions
with FIFOs.
+
+ int open_readbcoe (char const *file)
+Same as above, but the file is opened close-on-exec.
+
+
int open_excl (char const *file)
Opens file in write-only, non-blocking mode, with the
@@ -277,6 +294,13 @@ additional O_EXCL and O_CREAT flags.
Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+ int open_exclcoe (char const *file)
+Opens file in write-only, non-blocking mode, close-on-exec, with the
+additional O_EXCL and O_CREAT flags.
+Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+
int open_append (char const *file)
Opens file in write-only, non-blocking mode, with the
@@ -284,6 +308,13 @@ additional O_APPEND and O_CREAT flags.
Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+ int open_appendcoe (char const *file)
+Opens file in write-only, non-blocking mode, close-on-exec, with the
+additional O_APPEND and O_CREAT flags.
+Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+
int open_trunc (char const *file)
Opens file in write-only, non-blocking mode, with the
@@ -291,6 +322,13 @@ additional O_TRUNC and O_CREAT flags.
Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+ int open_trunccoe (char const *file)
+Opens file in write-only, non-blocking mode, close-on-exec, with the
+additional O_TRUNC and O_CREAT flags.
+Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+
int open_create (char const *file)
Opens file in write-only, non-blocking mode, with the
@@ -298,12 +336,25 @@ additional O_CREAT flag.
Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+ int open_createcoe (char const *file)
+Opens file in write-only, non-blocking mode, close-on-exec, with the
+additional O_CREAT flag.
+Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+
int open_write (char const *file)
Opens file in write-only, non-blocking mode.
Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+ int open_writecoe (char const *file)
+Opens file in write-only, non-blocking mode, close-on-exec.
+Returns a valid fd number if it succeeds, or -1 (and sets errno) if it fails.
+
+
Executable search and execution, and environment
diff --git a/doc/license.html b/doc/license.html
index 27bbf9f..9aae77e 100644
--- a/doc/license.html
+++ b/doc/license.html
@@ -74,7 +74,7 @@ color, or different text font.
I am aware that the previous restrictions sound completely
ridiculous while the official skalibs documentation is incomplete.
-As of 2.9.3.0, I'm not going to enforce those restrictions, but if you're
+As of 2.9.4.0, I'm not going to enforce those restrictions, but if you're
going to provide documentation for skalibs, don't keep it to yourself,
please send it to me instead. :-)
diff --git a/doc/upgrade.html b/doc/upgrade.html
index e59df35..0f1aee8 100644
--- a/doc/upgrade.html
+++ b/doc/upgrade.html
@@ -16,6 +16,13 @@
skarnet.org
+ in 2.9.4.0
+
+
+ - New open*coe functions, which are O_CLOEXEC versions of the
+djbunix.h functions without coe.
+
+
in 2.9.3.0
diff --git a/package/info b/package/info
index dc93a07..5d41757 100644
--- a/package/info
+++ b/package/info
@@ -1,4 +1,4 @@
package=skalibs
-version=2.9.3.0
+version=2.9.4.0
category=prog
package_macro_name=SKALIBS
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h
index fe8c2f9..2a6fdd4 100644
--- a/src/include/skalibs/djbunix.h
+++ b/src/include/skalibs/djbunix.h
@@ -43,13 +43,21 @@ extern void lock_unx (int) ;
extern int open2 (char const *, unsigned int) ;
extern int open3 (char const *, unsigned int, unsigned int) ;
extern int open_read (char const *) ;
+extern int open_readcoe (char const *) ;
extern int openb_read (char const *) ;
+extern int openb_readcoe (char const *) ;
extern int open_readb (char const *) ;
+extern int open_readbcoe (char const *) ;
extern int open_excl (char const *) ;
+extern int open_exclcoe (char const *) ;
extern int open_append (char const *) ;
+extern int open_appendcoe (char const *) ;
extern int open_create (char const *) ;
+extern int open_createcoe (char const *) ;
extern int open_trunc (char const *) ;
+extern int open_trunccoe (char const *) ;
extern int open_write (char const *) ;
+extern int open_writecoe (char const *) ;
extern int socket_internal (int, int, int, unsigned int) ;
extern int socketpair_internal (int, int, int, unsigned int, int *) ;
diff --git a/src/libstddjb/open_appendcoe.c b/src/libstddjb/open_appendcoe.c
new file mode 100644
index 0000000..3bda62e
--- /dev/null
+++ b/src/libstddjb/open_appendcoe.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include
+#include
+#include
+
+int open_appendcoe (char const *fn)
+{
+ return open3(fn, O_WRONLY | O_NONBLOCK | O_APPEND | O_CREAT | O_CLOEXEC, 0666) ;
+}
diff --git a/src/libstddjb/open_createcoe.c b/src/libstddjb/open_createcoe.c
new file mode 100644
index 0000000..4f42f78
--- /dev/null
+++ b/src/libstddjb/open_createcoe.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include
+#include
+#include
+
+int open_createcoe (char const *fn)
+{
+ return open3(fn, O_WRONLY | O_NONBLOCK | O_CREAT | O_CLOEXEC, 0666) ;
+}
diff --git a/src/libstddjb/open_exclcoe.c b/src/libstddjb/open_exclcoe.c
new file mode 100644
index 0000000..b24786c
--- /dev/null
+++ b/src/libstddjb/open_exclcoe.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include
+#include
+#include
+
+int open_exclcoe (char const *fn)
+{
+ return open3(fn, O_WRONLY | O_CREAT | O_EXCL | O_NONBLOCK | O_CLOEXEC, 0666) ;
+}
diff --git a/src/libstddjb/open_readbcoe.c b/src/libstddjb/open_readbcoe.c
new file mode 100644
index 0000000..d461854
--- /dev/null
+++ b/src/libstddjb/open_readbcoe.c
@@ -0,0 +1,15 @@
+/* ISC license. */
+
+#include
+
+int open_readbcoe (char const *fn)
+{
+ int fd = open_readbcoe(fn) ;
+ if (fd < 0) return -1 ;
+ if (ndelay_off(fd) < 0)
+ {
+ fd_close(fd) ;
+ return -1 ;
+ }
+ return fd ;
+}
diff --git a/src/libstddjb/open_readcoe.c b/src/libstddjb/open_readcoe.c
new file mode 100644
index 0000000..cd6a69d
--- /dev/null
+++ b/src/libstddjb/open_readcoe.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include
+#include
+#include
+
+int open_readcoe (char const *fn)
+{
+ return open2(fn, O_RDONLY | O_NONBLOCK | O_CLOEXEC) ;
+}
diff --git a/src/libstddjb/open_trunccoe.c b/src/libstddjb/open_trunccoe.c
new file mode 100644
index 0000000..3be3df6
--- /dev/null
+++ b/src/libstddjb/open_trunccoe.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include
+#include
+#include
+
+int open_trunccoe (char const *fn)
+{
+ return open3(fn, O_WRONLY | O_NONBLOCK | O_TRUNC | O_CREAT | O_CLOEXEC, 0666) ;
+}
diff --git a/src/libstddjb/open_writecoe.c b/src/libstddjb/open_writecoe.c
new file mode 100644
index 0000000..d04c4c5
--- /dev/null
+++ b/src/libstddjb/open_writecoe.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include
+#include
+#include
+
+int open_writecoe (char const *fn)
+{
+ return open2(fn, O_WRONLY | O_NONBLOCK | O_CLOEXEC) ;
+}
diff --git a/src/libstddjb/openb_readcoe.c b/src/libstddjb/openb_readcoe.c
new file mode 100644
index 0000000..933830e
--- /dev/null
+++ b/src/libstddjb/openb_readcoe.c
@@ -0,0 +1,10 @@
+/* ISC license. */
+
+#include
+#include
+#include
+
+int openb_readcoe (char const *fn)
+{
+ return open2(fn, O_RDONLY | O_CLOEXEC) ;
+}
diff --git a/src/libstddjb/openreadfileclose.c b/src/libstddjb/openreadfileclose.c
index baed267..95895e8 100644
--- a/src/libstddjb/openreadfileclose.c
+++ b/src/libstddjb/openreadfileclose.c
@@ -8,7 +8,7 @@
int openreadfileclose (char const *file, stralloc *sa, size_t limit)
{
size_t n ;
- int fd = open_readb(file) ;
+ int fd = openb_readcoe(file) ;
if (fd < 0) return 0 ;
{
struct stat st ;
diff --git a/src/libstddjb/openreadnclose.c b/src/libstddjb/openreadnclose.c
index e765499..0853c87 100644
--- a/src/libstddjb/openreadnclose.c
+++ b/src/libstddjb/openreadnclose.c
@@ -22,12 +22,12 @@ static ssize_t readnclose (int fd, char *s, size_t n)
ssize_t openreadnclose (char const *file, char *s, size_t n)
{
- int fd = open_readb(file) ;
+ int fd = openb_readcoe(file) ;
return fd < 0 ? fd : readnclose(fd, s, n) ;
}
ssize_t openreadnclose_nb (char const *file, char *s, size_t n)
{
- int fd = open_read(file) ;
+ int fd = open_readcoe(file) ;
return fd < 0 ? fd : readnclose(fd, s, n) ;
}
diff --git a/src/libstddjb/openslurpclose.c b/src/libstddjb/openslurpclose.c
index 50d361e..6a431d0 100644
--- a/src/libstddjb/openslurpclose.c
+++ b/src/libstddjb/openslurpclose.c
@@ -6,7 +6,7 @@
int openslurpclose (stralloc *sa, char const *fn)
{
int r ;
- int fd = open_readb(fn) ;
+ int fd = openb_readcoe(fn) ;
if (fd == -1) return 0 ;
r = slurp(sa, fd) ;
fd_close(fd) ;
diff --git a/src/libstddjb/openwritenclose_unsafe.c b/src/libstddjb/openwritenclose_unsafe.c
index 7969e4f..893fc3a 100644
--- a/src/libstddjb/openwritenclose_unsafe.c
+++ b/src/libstddjb/openwritenclose_unsafe.c
@@ -6,7 +6,7 @@
int openwritenclose_unsafe_internal (char const *fn, char const *s, size_t len, dev_t *dev, ino_t *ino, int dosync)
{
- int fd = open_trunc(fn) ;
+ int fd = open_trunccoe(fn) ;
if (fd < 0) return 0 ;
if (!writenclose_unsafe_internal(fd, s, len, dev, ino, dosync))
{
diff --git a/src/libstddjb/openwritevnclose_unsafe.c b/src/libstddjb/openwritevnclose_unsafe.c
index f3e6a6a..d707fb0 100644
--- a/src/libstddjb/openwritevnclose_unsafe.c
+++ b/src/libstddjb/openwritevnclose_unsafe.c
@@ -8,7 +8,7 @@
int openwritevnclose_unsafe_internal (char const *fn, struct iovec const *v, unsigned int vlen, dev_t *dev, ino_t *ino, int dosync)
{
- int fd = open_trunc(fn) ;
+ int fd = open_trunccoe(fn) ;
if (fd < 0) return 0 ;
if (!writevnclose_unsafe_internal(fd, v, vlen, dev, ino, dosync))
{
--
cgit v1.2.3