summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/djbunix.h2
-rw-r--r--src/include/skalibs/fcntl.h20
-rw-r--r--src/include/skalibs/gol.h32
-rw-r--r--src/include/skalibs/socket.h2
-rw-r--r--src/libposixplz/mkptemp2.c2
-rw-r--r--src/libstddjb/coe.c2
-rw-r--r--src/libstddjb/fd_ensure_open.c2
-rw-r--r--src/libstddjb/fd_islocked.c2
-rw-r--r--src/libstddjb/fd_lock.c2
-rw-r--r--src/libstddjb/fd_unlock.c2
-rw-r--r--src/libstddjb/filecopy_unsafe.c2
-rw-r--r--src/libstddjb/gol.c52
-rw-r--r--src/libstddjb/gol_argv.c26
-rw-r--r--src/libstddjb/hiercopy_internal.c2
-rw-r--r--src/libstddjb/ipc_accept.c2
-rw-r--r--src/libstddjb/ipc_bind_reuse_lock_perms.c2
-rw-r--r--src/libstddjb/ndelay_off.c2
-rw-r--r--src/libstddjb/ndelay_on.c2
-rw-r--r--src/libstddjb/open2.c28
-rw-r--r--src/libstddjb/open3.c28
-rw-r--r--src/libstddjb/open_append.c2
-rw-r--r--src/libstddjb/open_create.c2
-rw-r--r--src/libstddjb/open_excl.c2
-rw-r--r--src/libstddjb/open_read.c2
-rw-r--r--src/libstddjb/open_trunc.c2
-rw-r--r--src/libstddjb/open_write.c2
-rw-r--r--src/libstddjb/openb_read.c2
-rw-r--r--src/libstddjb/openbc_read.c2
-rw-r--r--src/libstddjb/openc_append.c2
-rw-r--r--src/libstddjb/openc_create.c2
-rw-r--r--src/libstddjb/openc_excl.c2
-rw-r--r--src/libstddjb/openc_read.c2
-rw-r--r--src/libstddjb/openc_trunc.c2
-rw-r--r--src/libstddjb/openc_write.c2
-rw-r--r--src/libstddjb/pipe_internal.c2
-rw-r--r--src/libstddjb/socket_accept4.c2
-rw-r--r--src/libstddjb/socket_accept6.c2
-rw-r--r--src/libstddjb/socket_internal.c2
-rw-r--r--src/libstddjb/socketpair_internal.c3
-rw-r--r--src/libstddjb/uncoe.c2
-rw-r--r--src/libunixonacid/access_at.c2
-rw-r--r--src/libunixonacid/open2_at.c7
-rw-r--r--src/libunixonacid/open3_at.c7
-rw-r--r--src/libunixonacid/open_appendat.c3
-rw-r--r--src/libunixonacid/open_readat.c2
-rw-r--r--src/libunixonacid/open_truncat.c2
-rw-r--r--src/libunixonacid/open_writeat.c2
-rw-r--r--src/libunixonacid/openc_appendat.c2
-rw-r--r--src/libunixonacid/openc_readat.c3
-rw-r--r--src/libunixonacid/openc_truncat.c3
-rw-r--r--src/libunixonacid/openc_writeat.c3
-rw-r--r--src/libunixonacid/stat_at.c8
-rw-r--r--src/libunixonacid/textclient_server_init_frompipe.c2
-rw-r--r--src/sysdeps/tryocloexec.c5
54 files changed, 247 insertions, 59 deletions
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h
index 68ec3b7..5bef6ec 100644
--- a/src/include/skalibs/djbunix.h
+++ b/src/include/skalibs/djbunix.h
@@ -6,11 +6,11 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
-#include <fcntl.h>
#include <skalibs/gccattributes.h>
#include <skalibs/stralloc.h>
#include <skalibs/devino.h>
+#include <skalibs/fcntl.h>
extern int coe (int) ;
extern int uncoe (int) ;
diff --git a/src/include/skalibs/fcntl.h b/src/include/skalibs/fcntl.h
new file mode 100644
index 0000000..fa91343
--- /dev/null
+++ b/src/include/skalibs/fcntl.h
@@ -0,0 +1,20 @@
+/* ISC license. */
+
+#ifndef SKALIBS_FCNTL_H
+#define SKALIBS_FCNTL_H
+
+#include <fcntl.h>
+
+ /*
+ Old MacOS X doesn't have O_CLOEXEC.
+ We define it to something completely out of the way so we
+ can still use it in userspace.
+ Workarounds in syscalls will be enabled via the
+ SKALIBS_HASOCLOEXEC sysdep.
+ */
+
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0x40000000
+#endif
+
+#endif
diff --git a/src/include/skalibs/gol.h b/src/include/skalibs/gol.h
new file mode 100644
index 0000000..bcab96c
--- /dev/null
+++ b/src/include/skalibs/gol.h
@@ -0,0 +1,32 @@
+/* ISC license. */
+
+#ifndef SKALIBS_GOL_H
+#define SKALIBS_GOL_H
+
+ /* Parsing of long (and short) options. */
+
+#include <stdint.h>
+
+#include <skalibs/uint64.h>
+
+typedef struct gol_bool_s gol_bool, gol_bool ;
+struct gol_bool_s
+{
+ char const *lo ;
+ uint8_t so : 7 ;
+ uint8_t set : 1 ;
+ uint64_t mask ;
+} ;
+
+typedef struct gol_arg_s gol_arg, gol_arg_ref ;
+struct gol_arg_s
+{
+ char const *lo ;
+ uint8_t so : 7 ;
+ unsigned int i ;
+} ;
+
+extern int gol (char const *const *, unsigned int, gol_bool const *, unsigned int, gol_arg const *a, unsigned int, uint64_t *, char const **, int *) ;
+extern unsigned int gol_argv (int, char const *const *, gol_bool const *, unsigned int, gol_arg const *a, unsigned int, uint64_t *, char const **) ;
+
+#endif
diff --git a/src/include/skalibs/socket.h b/src/include/skalibs/socket.h
index 85340bb..f13b2ee 100644
--- a/src/include/skalibs/socket.h
+++ b/src/include/skalibs/socket.h
@@ -5,11 +5,11 @@
#include <stddef.h>
#include <stdint.h>
-#include <fcntl.h>
#include <skalibs/gccattributes.h>
#include <skalibs/posixplz.h>
#include <skalibs/tai.h>
+#include <skalibs/fcntl.h>
typedef ssize_t socket_io_func (int, char *, size_t, char *, uint16_t *) ;
typedef socket_io_func *socket_io_func_ref ;
diff --git a/src/libposixplz/mkptemp2.c b/src/libposixplz/mkptemp2.c
index e4e9120..4e4f64a 100644
--- a/src/libposixplz/mkptemp2.c
+++ b/src/libposixplz/mkptemp2.c
@@ -1,8 +1,8 @@
/* ISC license. */
-#include <fcntl.h>
#include <sys/stat.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/posixplz.h>
diff --git a/src/libstddjb/coe.c b/src/libstddjb/coe.c
index a32c4ef..469a7c5 100644
--- a/src/libstddjb/coe.c
+++ b/src/libstddjb/coe.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int coe (int fd)
diff --git a/src/libstddjb/fd_ensure_open.c b/src/libstddjb/fd_ensure_open.c
index 4c1b63c..2867da1 100644
--- a/src/libstddjb/fd_ensure_open.c
+++ b/src/libstddjb/fd_ensure_open.c
@@ -1,8 +1,8 @@
/* ISC license. */
#include <errno.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int fd_ensure_open (int fd, int w)
diff --git a/src/libstddjb/fd_islocked.c b/src/libstddjb/fd_islocked.c
index 50603c0..6089ee8 100644
--- a/src/libstddjb/fd_islocked.c
+++ b/src/libstddjb/fd_islocked.c
@@ -1,8 +1,8 @@
/* ISC license. */
-#include <fcntl.h>
#include <unistd.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int fd_islocked (int fd)
diff --git a/src/libstddjb/fd_lock.c b/src/libstddjb/fd_lock.c
index a4ebaa5..e5d8a42 100644
--- a/src/libstddjb/fd_lock.c
+++ b/src/libstddjb/fd_lock.c
@@ -1,10 +1,10 @@
/* ISC license. */
-#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <skalibs/error.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int fd_lock (int fd, int w, int nb)
diff --git a/src/libstddjb/fd_unlock.c b/src/libstddjb/fd_unlock.c
index 0e6ac0e..64984b9 100644
--- a/src/libstddjb/fd_unlock.c
+++ b/src/libstddjb/fd_unlock.c
@@ -1,9 +1,9 @@
/* ISC license. */
-#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
void fd_unlock (int fd)
diff --git a/src/libstddjb/filecopy_unsafe.c b/src/libstddjb/filecopy_unsafe.c
index a6410c1..41f33bd 100644
--- a/src/libstddjb/filecopy_unsafe.c
+++ b/src/libstddjb/filecopy_unsafe.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int filecopy_unsafe (char const *src, char const *dst, unsigned int mode)
diff --git a/src/libstddjb/gol.c b/src/libstddjb/gol.c
new file mode 100644
index 0000000..e61d7f3
--- /dev/null
+++ b/src/libstddjb/gol.c
@@ -0,0 +1,52 @@
+/* ISC license. */
+
+#include <string.h>
+
+#include <skalibs/gol.h>
+
+int gol (char const *const *argv, unsigned int argc, gol_bool const *b, unsigned int bn, gol_arg const *a, unsigned int an, uint64_t *br, char const **ar, int *problem)
+{
+ for (unsigned int i = 0 ; i < argc ; i++)
+ {
+ if (argv[i][0] != '-' || !argv[i][1]) return i ;
+ if (argv[i][1] == '-')
+ {
+ unsigned int j = 0 ;
+ char const *x ;
+ if (!argv[i][2]) return i+1 ;
+ x = strchr(argv[i]+2, '=') ;
+ if (x)
+ {
+ size_t len = x - argv[i] - 2 ;
+ for (; j < an ; j++) if (!strncmp(argv[i] + 2, a[j].lo, len) && !a[j].lo[len]) break ;
+ if (j >= an) return (*problem = -1, -1-i) ;
+ ar[a[j].i] = x + 1 ;
+ }
+ else
+ {
+ for (; j < bn ; j++) if (!strcmp(argv[i] + 2, b[j].lo)) break ;
+ if (j >= bn) return (*problem = -1, -1-i) ;
+ if (b[j].set) *br |= b[j].mask ; else *br &= b[j].mask ;
+ }
+ }
+ else
+ {
+ char const *p = argv[i] + 1 ;
+ for (; !*p ; p++)
+ {
+ unsigned int j = 0 ;
+ for (; j < an ; j++) if (*p == a[j].so) break ;
+ if (j < an)
+ {
+ if (p[1]) ar[a[j].i] == p + 1 ;
+ else if (i+1 < argc && strcmp(argv[i+1], "--")) ar[a[j].i] = argv[++i] ;
+ break ;
+ }
+ for (j = 0 ; j < bn ; j++) if (*p == b[j].so) break ;
+ if (j >= bn) return (*problem = p - argv[i], -1-i) ;
+ if (b[j].set) *br |= b[j].mask ; else *br &= b[j].mask ;
+ }
+ }
+ }
+ return argc ;
+}
diff --git a/src/libstddjb/gol_argv.c b/src/libstddjb/gol_argv.c
new file mode 100644
index 0000000..2538f5a
--- /dev/null
+++ b/src/libstddjb/gol_argv.c
@@ -0,0 +1,26 @@
+/* ISC license. */
+
+#include <string.h>
+
+#include <skalibs/gol.h>
+#include <skalibs/strerr.h>
+
+unsigned int gol_argv (int argc, char const *const *argv, gol_bool const *b, unsigned int bn, gol_arg const *a, unsigned int an, uint64_t *br, char const **ar)
+{
+ int problem = 0 ;
+ int r ;
+ if (!argc) strerr_diefu1x(100, "gol: invalid argv") ;
+ if (argc == 1) return 1 ;
+ r = gol(argv + 1, argc - 1, b, bn, a, an, br, ar, &problem) ;
+
+ if (r < 0)
+ {
+ if (problem >= 0)
+ {
+ char s[2] = { argv[-r][problem], 0 } ;
+ strerr_dief4x(100, "unrecognized ", "short", "option: ", s) ;
+ }
+ else strerr_dief3x(100, "unrecognized ", "option: ", argv[-r]) ;
+ }
+ else return r + 1 ;
+}
diff --git a/src/libstddjb/hiercopy_internal.c b/src/libstddjb/hiercopy_internal.c
index c512463..5d216a3 100644
--- a/src/libstddjb/hiercopy_internal.c
+++ b/src/libstddjb/hiercopy_internal.c
@@ -4,10 +4,10 @@
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
-#include <fcntl.h>
#include <skalibs/stralloc.h>
#include <skalibs/direntry.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
static int dircopy (char const *src, char const *dst, mode_t mode, stralloc *tmp, unsigned int options)
diff --git a/src/libstddjb/ipc_accept.c b/src/libstddjb/ipc_accept.c
index 9d5d82c..83886ff 100644
--- a/src/libstddjb/ipc_accept.c
+++ b/src/libstddjb/ipc_accept.c
@@ -6,9 +6,9 @@
#include <sys/un.h>
#include <string.h>
#include <errno.h>
-#include <fcntl.h>
#include <skalibs/bytestr.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
diff --git a/src/libstddjb/ipc_bind_reuse_lock_perms.c b/src/libstddjb/ipc_bind_reuse_lock_perms.c
index 6e4d9ff..f47ba19 100644
--- a/src/libstddjb/ipc_bind_reuse_lock_perms.c
+++ b/src/libstddjb/ipc_bind_reuse_lock_perms.c
@@ -2,13 +2,13 @@
#include <skalibs/nonposix.h>
-#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
diff --git a/src/libstddjb/ndelay_off.c b/src/libstddjb/ndelay_off.c
index 5ea68c6..1d23f08 100644
--- a/src/libstddjb/ndelay_off.c
+++ b/src/libstddjb/ndelay_off.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int ndelay_off (int fd)
diff --git a/src/libstddjb/ndelay_on.c b/src/libstddjb/ndelay_on.c
index 1bf9527..2a899b8 100644
--- a/src/libstddjb/ndelay_on.c
+++ b/src/libstddjb/ndelay_on.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int ndelay_on (int fd)
diff --git a/src/libstddjb/open2.c b/src/libstddjb/open2.c
index 1d2682e..0f23183 100644
--- a/src/libstddjb/open2.c
+++ b/src/libstddjb/open2.c
@@ -1,14 +1,38 @@
/* ISC license. */
+#include <skalibs/sysdeps.h>
#include <skalibs/nonposix.h>
+
#include <sys/stat.h>
-#include <fcntl.h>
#include <errno.h>
+#include <skalibs/fcntl.h>
+#include <skalibs/djbunix.h>
+
+#ifdef SKALIBS_HASOCLOEXEC
+
int open2 (char const *s, unsigned int flags)
{
int r ;
do r = open(s, flags) ;
- while ((r == -1) && (errno == EINTR)) ;
+ while (r == -1 && errno == EINTR) ;
return r ;
}
+
+#else
+
+int open2 (char const *s, unsigned int flags)
+{
+ int fd ;
+ do fd = open(s, flags & ~O_CLOEXEC) ;
+ while (fd == -1 && errno == EINTR) ;
+ if (fd == -1) return -1 ;
+ if (flags & O_CLOEXEC && coe(fd) == -1)
+ {
+ fd_close(fd) ;
+ return -1 ;
+ }
+ return fd ;
+}
+
+#endif
diff --git a/src/libstddjb/open3.c b/src/libstddjb/open3.c
index 21fd904..a9ff9e6 100644
--- a/src/libstddjb/open3.c
+++ b/src/libstddjb/open3.c
@@ -1,14 +1,38 @@
/* ISC license. */
+#include <skalibs/sysdeps.h>
#include <skalibs/nonposix.h>
+
#include <sys/stat.h>
-#include <fcntl.h>
#include <errno.h>
+#include <skalibs/fcntl.h>
+#include <skalibs/djbunix.h>
+
+#ifdef SKALIBS_HASOCLOEXEC
+
int open3 (char const *s, unsigned int flags, unsigned int mode)
{
int r ;
do r = open(s, flags, mode) ;
- while ((r == -1) && (errno == EINTR)) ;
+ while (r == -1 && errno == EINTR) ;
return r ;
}
+
+#else
+
+int open3 (char const *s, unsigned int flags, unsigned int mode)
+{
+ int fd ;
+ do fd = open(s, flags & ~O_CLOEXEC, mode) ;
+ while (fd == -1 && errno == EINTR) ;
+ if (fd == -1) return -1 ;
+ if (flags & O_CLOEXEC && coe(fd) == -1)
+ {
+ fd_close(fd) ;
+ return -1 ;
+ }
+ return fd ;
+}
+
+#endif
diff --git a/src/libstddjb/open_append.c b/src/libstddjb/open_append.c
index 7486312..74f1bca 100644
--- a/src/libstddjb/open_append.c
+++ b/src/libstddjb/open_append.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int open_append (char const *fn)
diff --git a/src/libstddjb/open_create.c b/src/libstddjb/open_create.c
index db072d1..6eeb57a 100644
--- a/src/libstddjb/open_create.c
+++ b/src/libstddjb/open_create.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int open_create (char const *fn)
diff --git a/src/libstddjb/open_excl.c b/src/libstddjb/open_excl.c
index 83c7770..e93d194 100644
--- a/src/libstddjb/open_excl.c
+++ b/src/libstddjb/open_excl.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int open_excl (char const *fn)
diff --git a/src/libstddjb/open_read.c b/src/libstddjb/open_read.c
index cc1b191..327dd08 100644
--- a/src/libstddjb/open_read.c
+++ b/src/libstddjb/open_read.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int open_read (char const *fn)
diff --git a/src/libstddjb/open_trunc.c b/src/libstddjb/open_trunc.c
index b34e3c2..8333934 100644
--- a/src/libstddjb/open_trunc.c
+++ b/src/libstddjb/open_trunc.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int open_trunc (char const *fn)
diff --git a/src/libstddjb/open_write.c b/src/libstddjb/open_write.c
index 42a92c3..14045c7 100644
--- a/src/libstddjb/open_write.c
+++ b/src/libstddjb/open_write.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int open_write (char const *fn)
diff --git a/src/libstddjb/openb_read.c b/src/libstddjb/openb_read.c
index 19ec073..cd7925a 100644
--- a/src/libstddjb/openb_read.c
+++ b/src/libstddjb/openb_read.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openb_read (char const *fn)
diff --git a/src/libstddjb/openbc_read.c b/src/libstddjb/openbc_read.c
index 4783780..bd4713e 100644
--- a/src/libstddjb/openbc_read.c
+++ b/src/libstddjb/openbc_read.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openbc_read (char const *fn)
diff --git a/src/libstddjb/openc_append.c b/src/libstddjb/openc_append.c
index 9765aa6..e0375dd 100644
--- a/src/libstddjb/openc_append.c
+++ b/src/libstddjb/openc_append.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openc_append (char const *fn)
diff --git a/src/libstddjb/openc_create.c b/src/libstddjb/openc_create.c
index 2c0dd86..98e535b 100644
--- a/src/libstddjb/openc_create.c
+++ b/src/libstddjb/openc_create.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openc_create (char const *fn)
diff --git a/src/libstddjb/openc_excl.c b/src/libstddjb/openc_excl.c
index 9a45913..97e5531 100644
--- a/src/libstddjb/openc_excl.c
+++ b/src/libstddjb/openc_excl.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openc_excl (char const *fn)
diff --git a/src/libstddjb/openc_read.c b/src/libstddjb/openc_read.c
index 57a23bc..6cb77fe 100644
--- a/src/libstddjb/openc_read.c
+++ b/src/libstddjb/openc_read.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openc_read (char const *fn)
diff --git a/src/libstddjb/openc_trunc.c b/src/libstddjb/openc_trunc.c
index ca39160..bda44be 100644
--- a/src/libstddjb/openc_trunc.c
+++ b/src/libstddjb/openc_trunc.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openc_trunc (char const *fn)
diff --git a/src/libstddjb/openc_write.c b/src/libstddjb/openc_write.c
index 518c460..4310cfb 100644
--- a/src/libstddjb/openc_write.c
+++ b/src/libstddjb/openc_write.c
@@ -1,7 +1,7 @@
/* ISC license. */
#include <skalibs/nonposix.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int openc_write (char const *fn)
diff --git a/src/libstddjb/pipe_internal.c b/src/libstddjb/pipe_internal.c
index dc7cfe6..972f595 100644
--- a/src/libstddjb/pipe_internal.c
+++ b/src/libstddjb/pipe_internal.c
@@ -17,8 +17,8 @@ int pipe_internal (int *p, unsigned int flags)
#else
#include <unistd.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int pipe_internal (int *p, unsigned int flags)
diff --git a/src/libstddjb/socket_accept4.c b/src/libstddjb/socket_accept4.c
index 36f3dc2..0c11023 100644
--- a/src/libstddjb/socket_accept4.c
+++ b/src/libstddjb/socket_accept4.c
@@ -7,9 +7,9 @@
#include <netinet/in.h>
#include <string.h>
#include <errno.h>
-#include <fcntl.h>
#include <skalibs/uint16.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
diff --git a/src/libstddjb/socket_accept6.c b/src/libstddjb/socket_accept6.c
index 2c18540..229178d 100644
--- a/src/libstddjb/socket_accept6.c
+++ b/src/libstddjb/socket_accept6.c
@@ -7,9 +7,9 @@
#include <netinet/in.h>
#include <string.h>
#include <errno.h>
-#include <fcntl.h>
#include <skalibs/uint16.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/ip46.h>
#include <skalibs/socket.h>
diff --git a/src/libstddjb/socket_internal.c b/src/libstddjb/socket_internal.c
index 39c6e38..3371b9a 100644
--- a/src/libstddjb/socket_internal.c
+++ b/src/libstddjb/socket_internal.c
@@ -4,8 +4,8 @@
#include <skalibs/nonposix.h>
#include <sys/socket.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
diff --git a/src/libstddjb/socketpair_internal.c b/src/libstddjb/socketpair_internal.c
index 0cedce2..8e46374 100644
--- a/src/libstddjb/socketpair_internal.c
+++ b/src/libstddjb/socketpair_internal.c
@@ -2,10 +2,11 @@
#include <skalibs/sysdeps.h>
#include <skalibs/nonposix.h>
+
#include <sys/socket.h>
#include <errno.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/socket.h>
diff --git a/src/libstddjb/uncoe.c b/src/libstddjb/uncoe.c
index be7b90c..55804ff 100644
--- a/src/libstddjb/uncoe.c
+++ b/src/libstddjb/uncoe.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
int uncoe (int fd)
diff --git a/src/libunixonacid/access_at.c b/src/libunixonacid/access_at.c
index 69fdce4..e7f988c 100644
--- a/src/libunixonacid/access_at.c
+++ b/src/libunixonacid/access_at.c
@@ -10,9 +10,9 @@
#include <skalibs/nonposix.h>
-#include <fcntl.h>
#include <unistd.h>
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int access_at (int dirfd, char const *file, int amode, unsigned int flag)
diff --git a/src/libunixonacid/open2_at.c b/src/libunixonacid/open2_at.c
index 76d79cc..d96c0b7 100644
--- a/src/libunixonacid/open2_at.c
+++ b/src/libunixonacid/open2_at.c
@@ -11,14 +11,14 @@
#include <skalibs/nonposix.h>
#include <errno.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int open2_at (int dirfd, char const *file, int flags)
{
int fd ;
- do fd = openat(dirfd, file, flags) ;
+ do fd = openat(dirfd, file, flags) ; /* all systems supporting openat() have O_CLOEXEC */
while (fd == -1 && errno == EINTR) ;
return fd ;
}
@@ -26,8 +26,9 @@ int open2_at (int dirfd, char const *file, int flags)
#else
#include <sys/stat.h>
-#include <fcntl.h>
#include <errno.h>
+
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/unix-transactional.h>
diff --git a/src/libunixonacid/open3_at.c b/src/libunixonacid/open3_at.c
index 063092d..742a579 100644
--- a/src/libunixonacid/open3_at.c
+++ b/src/libunixonacid/open3_at.c
@@ -11,14 +11,14 @@
#include <skalibs/nonposix.h>
#include <errno.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int open3_at (int dirfd, char const *file, int flags, unsigned int mode)
{
int fd ;
- do fd = openat(dirfd, file, flags, mode) ;
+ do fd = openat(dirfd, file, flags, mode) ; /* all systems that support openat() have O_CLOEXEC */
while (fd == -1 && errno == EINTR) ;
return fd ;
}
@@ -26,8 +26,9 @@ int open3_at (int dirfd, char const *file, int flags, unsigned int mode)
#else
#include <sys/stat.h>
-#include <fcntl.h>
#include <errno.h>
+
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/unix-transactional.h>
diff --git a/src/libunixonacid/open_appendat.c b/src/libunixonacid/open_appendat.c
index 5ad73d1..66a3cb4 100644
--- a/src/libunixonacid/open_appendat.c
+++ b/src/libunixonacid/open_appendat.c
@@ -1,7 +1,8 @@
/* ISC license. */
#include <sys/stat.h>
-#include <fcntl.h>
+
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int open_appendat (int fd, char const *name)
diff --git a/src/libunixonacid/open_readat.c b/src/libunixonacid/open_readat.c
index 05f6926..7149329 100644
--- a/src/libunixonacid/open_readat.c
+++ b/src/libunixonacid/open_readat.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int open_readat (int fd, char const *name)
diff --git a/src/libunixonacid/open_truncat.c b/src/libunixonacid/open_truncat.c
index ce4f132..d7c61bf 100644
--- a/src/libunixonacid/open_truncat.c
+++ b/src/libunixonacid/open_truncat.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int open_truncat (int fd, char const *name)
diff --git a/src/libunixonacid/open_writeat.c b/src/libunixonacid/open_writeat.c
index 695e343..9206f08 100644
--- a/src/libunixonacid/open_writeat.c
+++ b/src/libunixonacid/open_writeat.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int open_writeat (int fd, char const *name)
diff --git a/src/libunixonacid/openc_appendat.c b/src/libunixonacid/openc_appendat.c
index 70b6df7..88228c5 100644
--- a/src/libunixonacid/openc_appendat.c
+++ b/src/libunixonacid/openc_appendat.c
@@ -1,8 +1,8 @@
/* ISC license. */
#include <sys/stat.h>
-#include <fcntl.h>
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int openc_appendat (int fd, char const *name)
diff --git a/src/libunixonacid/openc_readat.c b/src/libunixonacid/openc_readat.c
index dc092b6..3284977 100644
--- a/src/libunixonacid/openc_readat.c
+++ b/src/libunixonacid/openc_readat.c
@@ -1,7 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
-
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int openc_readat (int fd, char const *name)
diff --git a/src/libunixonacid/openc_truncat.c b/src/libunixonacid/openc_truncat.c
index 8ce50d2..55d1123 100644
--- a/src/libunixonacid/openc_truncat.c
+++ b/src/libunixonacid/openc_truncat.c
@@ -1,7 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
-
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int openc_truncat (int fd, char const *name)
diff --git a/src/libunixonacid/openc_writeat.c b/src/libunixonacid/openc_writeat.c
index e584e57..c79c652 100644
--- a/src/libunixonacid/openc_writeat.c
+++ b/src/libunixonacid/openc_writeat.c
@@ -1,7 +1,6 @@
/* ISC license. */
-#include <fcntl.h>
-
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int openc_writeat (int fd, char const *name)
diff --git a/src/libunixonacid/stat_at.c b/src/libunixonacid/stat_at.c
index 2d04d57..e4040d5 100644
--- a/src/libunixonacid/stat_at.c
+++ b/src/libunixonacid/stat_at.c
@@ -9,8 +9,10 @@
#endif
#include <skalibs/nonposix.h>
+
#include <sys/stat.h>
-#include <fcntl.h>
+
+#include <skalibs/fcntl.h>
#include <skalibs/unix-transactional.h>
int stat_at (int dirfd, char const *file, struct stat *st)
@@ -27,9 +29,11 @@ int lstat_at (int dirfd, char const *file, struct stat *st)
/* OpenBSD plz. lstat() is POSIX. */
#include <skalibs/nonposix.h>
+
#include <sys/stat.h>
-#include <fcntl.h>
#include <errno.h>
+
+#include <skalibs/fcntl.h>
#include <skalibs/djbunix.h>
#include <skalibs/unix-transactional.h>
diff --git a/src/libunixonacid/textclient_server_init_frompipe.c b/src/libunixonacid/textclient_server_init_frompipe.c
index d5d9d97..3909deb 100644
--- a/src/libunixonacid/textclient_server_init_frompipe.c
+++ b/src/libunixonacid/textclient_server_init_frompipe.c
@@ -2,9 +2,9 @@
#include <sys/uio.h>
#include <stdlib.h>
-#include <fcntl.h>
#include <errno.h>
+#include <skalibs/fcntl.h>
#include <skalibs/types.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/cspawn.h>
diff --git a/src/sysdeps/tryocloexec.c b/src/sysdeps/tryocloexec.c
new file mode 100644
index 0000000..bd318ae
--- /dev/null
+++ b/src/sysdeps/tryocloexec.c
@@ -0,0 +1,5 @@
+/* ISC license. */
+
+#include <fcntl.h>
+
+int dummy = O_CLOEXEC ;