From ea189862e2be9ebf35da6174b1ae0083a22cc9ee Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Wed, 9 Dec 2020 18:46:22 +0000 Subject: Add mkptemp2() --- src/libposixplz/mkptemp.c | 16 +--------------- src/libposixplz/mkptemp2.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 src/libposixplz/mkptemp2.c (limited to 'src/libposixplz') diff --git a/src/libposixplz/mkptemp.c b/src/libposixplz/mkptemp.c index 64ddb5c..2c3e817 100644 --- a/src/libposixplz/mkptemp.c +++ b/src/libposixplz/mkptemp.c @@ -1,22 +1,8 @@ /* ISC license. */ -#include - -#include #include -static int f (char const *fn, mode_t mode, void *data) -{ - mode_t m = umask(0) ; - int r = mkfifo(fn, mode) ; - umask(m) ; - if (r == -1) return -1 ; - r = open_readb(fn) ; - if (r == -1) unlink_void(fn) ; - return r ; -} - int mkptemp (char *s) { - return mkfiletemp(s, &f, 0600, 0) ; + return mkptemp2(s, 0) ; } 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 +#include + +#include +#include + +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) ; +} -- cgit v1.2.3