summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2024-05-03 21:01:48 +0000
committerLaurent Bercot <ska@appnovation.com>2024-05-03 21:01:48 +0000
commitc684d2df8c04554f79ada0c9bf5aa2e8c01aa82b (patch)
tree96bfdcfd6bed655dd991fc2e8d130a044ac7d1e4 /src
parent02926ee3447b1ea0d04b53b8fcb08d8b1a4deec5 (diff)
downloadskalibs-c684d2df8c04554f79ada0c9bf5aa2e8c01aa82b.tar.xz
Add mkptemp3
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/posixplz.h1
-rw-r--r--src/libposixplz/mkptemp2.c18
-rw-r--r--src/libposixplz/mkptemp3.c25
3 files changed, 27 insertions, 17 deletions
diff --git a/src/include/skalibs/posixplz.h b/src/include/skalibs/posixplz.h
index 9eef116..daf9cdd 100644
--- a/src/include/skalibs/posixplz.h
+++ b/src/include/skalibs/posixplz.h
@@ -43,6 +43,7 @@ extern int mkfiletemp (char *, create_func_ref, mode_t, void *) ;
extern int mklinktemp (char const *, char *, link_func_ref) ;
extern int mkptemp (char *) ;
extern int mkptemp2 (char *, unsigned int) ;
+extern int mkptemp3 (char *, mode_t, unsigned int) ;
extern int mkltemp (char const *, char *) ;
extern int mkhtemp (char const *, char *) ;
extern int mkctemp (char *, mode_t, dev_t) ;
diff --git a/src/libposixplz/mkptemp2.c b/src/libposixplz/mkptemp2.c
index 4e4f64a..b4f5df5 100644
--- a/src/libposixplz/mkptemp2.c
+++ b/src/libposixplz/mkptemp2.c
@@ -1,24 +1,8 @@
/* 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 ;
- 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) ;
+ return mkptemp3(s, 0600, flags) ;
}
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 ;
+}