skalibs

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

mkbtemp.c (465B)


      1 /* ISC license. */
      2 
      3 #include <sys/stat.h>
      4 
      5 #include <skalibs/djbunix.h>
      6 #include <skalibs/posixplz.h>
      7 
      8 static int f (char const *fn, mode_t mode, void *data)
      9 {
     10   dev_t *devp = data ;
     11   mode_t m = umask(0) ;
     12   int r = mknod(fn, (mode & 00777) | S_IFBLK, *devp) ;
     13   umask(m) ;
     14   if (r == -1) return -1 ;
     15   r = open_readb(fn) ;
     16   if (r == -1) unlink_void(fn) ;
     17   return r ;
     18 }
     19 
     20 int mkbtemp (char *s, mode_t mode, dev_t dev)
     21 {
     22   return mkfiletemp(s, &f, mode, &dev) ;
     23 }