summaryrefslogtreecommitdiff
path: root/src/libposixplz/mkptemp3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libposixplz/mkptemp3.c')
-rw-r--r--src/libposixplz/mkptemp3.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libposixplz/mkptemp3.c b/src/libposixplz/mkptemp3.c
new file mode 100644
index 0000000..4b75b4d
--- /dev/null
+++ b/src/libposixplz/mkptemp3.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <sys/stat.h>
+
+#include <skalibs/fcntl.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 ;
+ int r = mkfifo(fn, mode) ;
+ 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 mkptemp3 (char *s, mode_t mode, unsigned int flags)
+{
+ mode_t m = umask(0) ;
+ int r = mkfiletemp(s, &f, mode, &flags) ;
+ umask(m) ;
+ return r ;
+}