summaryrefslogtreecommitdiff
path: root/src/libposixplz/mkbtemp.c
blob: c4c62dfbf7287be298af6eacd6343a14965df9e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* ISC license. */

#include <sys/stat.h>

#include <skalibs/djbunix.h>
#include <skalibs/posixplz.h>

static int f (char const *fn, mode_t mode, void *data)
{
  dev_t *devp = data ;
  int r = mknod(fn, (mode & 00777) | S_IFBLK, *devp) ;
  if (r == -1) return -1 ;
  r = open_readb(fn) ;
  if (r == -1) unlink_void(fn) ;
  return r ;
}

int mkbtemp (char *s, mode_t mode, dev_t dev)
{
  return mkfiletemp(s, &f, mode, &dev) ;
}