skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit c684d2df8c04554f79ada0c9bf5aa2e8c01aa82b
parent 02926ee3447b1ea0d04b53b8fcb08d8b1a4deec5
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Fri,  3 May 2024 21:01:48 +0000

 Add mkptemp3

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
MNEWS | 1+
Mdoc/upgrade.html | 1+
Mpackage/deps.mak | 3++-
Msrc/include/skalibs/posixplz.h | 1+
Msrc/libposixplz/mkptemp2.c | 18+-----------------
Asrc/libposixplz/mkptemp3.c | 25+++++++++++++++++++++++++
6 files changed, 31 insertions(+), 18 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ; +}