diff options
Diffstat (limited to 'libc-top-half/musl/src/temp/mktemp.c')
-rw-r--r-- | libc-top-half/musl/src/temp/mktemp.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/temp/mktemp.c b/libc-top-half/musl/src/temp/mktemp.c new file mode 100644 index 0000000..7b3d264 --- /dev/null +++ b/libc-top-half/musl/src/temp/mktemp.c @@ -0,0 +1,30 @@ +#define _GNU_SOURCE +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <sys/stat.h> + +char *mktemp(char *template) +{ + size_t l = strlen(template); + int retries = 100; + struct stat st; + + if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) { + errno = EINVAL; + *template = 0; + return template; + } + + do { + __randname(template+l-6); + if (stat(template, &st)) { + if (errno != ENOENT) *template = 0; + return template; + } + } while (--retries); + + *template = 0; + errno = EEXIST; + return template; +} |