regex: character classes
[neatlibc.git] / mkstemp.c
blobc9c400397443d21f71e09b9bf02c02c097ef6a2b
1 #include <fcntl.h>
2 #include <string.h>
3 #include <unistd.h>
5 static int tmpid;
6 static char *digs = "0123456789abcdef";
8 int mkstemp(char *t)
10 char *x = t + strlen(t) - 6;
11 int fd;
12 int i;
13 if (strlen(t) < 6)
14 return -1;
15 for (i = 0; i < 6; i++)
16 x[i] = '0';
17 while ((fd = open(t, O_RDWR | O_EXCL | O_CREAT, 0600)) == -1) {
18 int n = ++tmpid;
19 for (i = 0; i < 6; i++) {
20 x[5 - i] = digs[n & 0x0f];
21 n <<= 4;
24 unlink(t);
25 return fd;