mkptemp3.c (628B)
1 /* ISC license. */ 2 3 #include <sys/stat.h> 4 5 #include <skalibs/fcntl.h> 6 #include <skalibs/djbunix.h> 7 #include <skalibs/posixplz.h> 8 9 static int f (char const *fn, mode_t mode, void *data) 10 { 11 unsigned int flags = *(unsigned int *)data ; 12 int r = mkfifo(fn, mode) ; 13 if (r == -1) return -1 ; 14 r = flags & O_NONBLOCK ? flags & O_CLOEXEC ? openc_read(fn) : open_read(fn) : flags & O_CLOEXEC ? openc_readb(fn) : open_readb(fn) ; 15 if (r == -1) unlink_void(fn) ; 16 return r ; 17 } 18 19 int mkptemp3 (char *s, mode_t mode, unsigned int flags) 20 { 21 mode_t m = umask(0) ; 22 int r = mkfiletemp(s, &f, mode, &flags) ; 23 umask(m) ; 24 return r ; 25 }