mkfiletemp.c (502B)
1 /* ISC license. */ 2 3 #include <string.h> 4 #include <errno.h> 5 6 #include <skalibs/random.h> 7 #include <skalibs/posixplz.h> 8 9 int mkfiletemp (char *s, create_func_ref f, mode_t mode, void *data) 10 { 11 size_t len = strlen(s) ; 12 size_t xlen = 0 ; 13 int r ; 14 for (; xlen < len ; xlen++) if (s[len - 1 - xlen] != 'X') break ; 15 if (xlen < 6) return (errno = EINVAL, -1) ; 16 do 17 { 18 random_name_early(s + len - xlen, xlen) ; 19 r = (*f)(s, mode, data) ; 20 } while (r == -1 && errno == EEXIST) ; 21 return r ; 22 }