diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | doc/upgrade.html | 1 | ||||
-rw-r--r-- | package/deps.mak | 3 | ||||
-rw-r--r-- | src/include/skalibs/posixplz.h | 1 | ||||
-rw-r--r-- | src/libposixplz/mkptemp2.c | 18 | ||||
-rw-r--r-- | src/libposixplz/mkptemp3.c | 25 |
6 files changed, 31 insertions, 18 deletions
diff --git a/NEWS b/NEWS index 1458371..b9fcab4 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ In 2.4.2.0 - Support for midipix and old MacOS X. (More sysdeps.) - New gol.h header (a take on getopt_long) + - New mkptemp3 function In 2.14.1.1 diff --git a/doc/upgrade.html b/doc/upgrade.html index 37215fc..dc7b334 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -20,6 +20,7 @@ <ul> <li> New <tt>skalibs/gol.h</tt> header, implementing long options. </li> + <li> New <tt>mkptemp3()</tt> function. </li> </ul> <h2> in 2.14.1.1 </h2> diff --git a/package/deps.mak b/package/deps.mak index 4d420c5..63d42a0 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -179,7 +179,8 @@ src/libposixplz/mkhtemp.o src/libposixplz/mkhtemp.lo: src/libposixplz/mkhtemp.c src/libposixplz/mklinktemp.o src/libposixplz/mklinktemp.lo: src/libposixplz/mklinktemp.c src/include/skalibs/djbunix.h src/libposixplz/posixplz-internal.h src/include/skalibs/posixplz.h src/libposixplz/mkltemp.o src/libposixplz/mkltemp.lo: src/libposixplz/mkltemp.c src/include/skalibs/posixplz.h src/libposixplz/mkptemp.o src/libposixplz/mkptemp.lo: src/libposixplz/mkptemp.c src/include/skalibs/posixplz.h -src/libposixplz/mkptemp2.o src/libposixplz/mkptemp2.lo: src/libposixplz/mkptemp2.c src/include/skalibs/djbunix.h src/include/skalibs/fcntl.h src/include/skalibs/posixplz.h +src/libposixplz/mkptemp2.o src/libposixplz/mkptemp2.lo: src/libposixplz/mkptemp2.c src/include/skalibs/posixplz.h +src/libposixplz/mkptemp3.o src/libposixplz/mkptemp3.lo: src/libposixplz/mkptemp3.c src/include/skalibs/djbunix.h src/include/skalibs/fcntl.h src/include/skalibs/posixplz.h src/libposixplz/munmap_void.o src/libposixplz/munmap_void.lo: src/libposixplz/munmap_void.c src/include/skalibs/posixplz.h src/libposixplz/setgroups.o src/libposixplz/setgroups.lo: src/libposixplz/setgroups.c src/include/skalibs/nonposix.h src/include/skalibs/posixishard.h src/include/skalibs/setgroups.h src/include/skalibs/sysdeps.h src/libposixplz/strcasestr.o src/libposixplz/strcasestr.lo: src/libposixplz/strcasestr.c src/include/skalibs/bytestr.h src/include/skalibs/sysdeps.h 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 ; +} |