remove leftover unused variable in mktemp after refactoring
[musl] / src / temp / mkostemps.c
1 #define _BSD_SOURCE
2 #include <string.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <errno.h>
6 #include "libc.h"
7
8 char *__randname(char *);
9
10 int __mkostemps(char *template, int len, int flags)
11 {
12         if (len < 0) return EINVAL;
13
14         size_t l = strlen(template)-len;
15         if (l < 6 || strncmp(template+l-6, "XXXXXX", 6)) {
16                 errno = EINVAL;
17                 *template = 0;
18                 return -1;
19         }
20
21         int fd, retries = 100;
22         while (retries--) {
23                 __randname(template+l-6);
24                 if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600))>=0)
25                         return fd;
26                 if (errno != EEXIST) return -1;
27         }
28         return -1;
29 }
30
31 weak_alias(__mkostemps, mkostemps);
32 weak_alias(__mkostemps, mkostemps64);