synccall: add separate exit_sem to fix thread release logic bug
[musl.git] / src / temp / mkdtemp.c
blob5708257bfecf6ae3e05a5e9fdd0e7054a96d0a7c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <errno.h>
4 #include <sys/stat.h>
6 char *mkdtemp(char *template)
8 size_t l = strlen(template);
9 int retries = 100;
11 if (l<6 || memcmp(template+l-6, "XXXXXX", 6)) {
12 errno = EINVAL;
13 return 0;
16 do {
17 __randname(template+l-6);
18 if (!mkdir(template, 0700)) return template;
19 } while (--retries && errno == EEXIST);
21 memcpy(template+l-6, "XXXXXX", 6);
22 return 0;