| Index: fusl/src/temp/mktemp.c
|
| diff --git a/fusl/src/temp/mktemp.c b/fusl/src/temp/mktemp.c
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4ab0df2069ac6d0c685ea2265f15d40596392217
|
| --- /dev/null
|
| +++ b/fusl/src/temp/mktemp.c
|
| @@ -0,0 +1,32 @@
|
| +#define _GNU_SOURCE
|
| +#include <string.h>
|
| +#include <stdlib.h>
|
| +#include <errno.h>
|
| +#include <sys/stat.h>
|
| +
|
| +char *__randname(char *);
|
| +
|
| +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;
|
| +}
|
|
|