summaryrefslogtreecommitdiff
path: root/src/libposixplz/mkptemp2.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-12-09 18:46:22 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-12-09 18:46:22 +0000
commitea189862e2be9ebf35da6174b1ae0083a22cc9ee (patch)
tree80324d68df13dfc519243118567df92a8e4e333a /src/libposixplz/mkptemp2.c
parentef7aef6ba0d90174e9079944eaf3010de3555cc0 (diff)
downloadskalibs-ea189862e2be9ebf35da6174b1ae0083a22cc9ee.tar.xz
Add mkptemp2()
Diffstat (limited to 'src/libposixplz/mkptemp2.c')
-rw-r--r--src/libposixplz/mkptemp2.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libposixplz/mkptemp2.c b/src/libposixplz/mkptemp2.c
new file mode 100644
index 0000000..e4e9120
--- /dev/null
+++ b/src/libposixplz/mkptemp2.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#include <skalibs/djbunix.h>
+#include <skalibs/posixplz.h>
+
+static int f (char const *fn, mode_t mode, void *data)
+{
+ unsigned int flags = *(unsigned int *)data ;
+ mode_t m = umask(0) ;
+ int r = mkfifo(fn, mode) ;
+ umask(m) ;
+ if (r == -1) return -1 ;
+ r = flags & O_NONBLOCK ? flags & O_CLOEXEC ? openc_read(fn) : open_read(fn) : flags & O_CLOEXEC ? openc_readb(fn) : open_readb(fn) ;
+ if (r == -1) unlink_void(fn) ;
+ return r ;
+}
+
+int mkptemp2 (char *s, unsigned int flags)
+{
+ return mkfiletemp(s, &f, 0600, &flags) ;
+}