diff options
-rw-r--r-- | sys/include/ape/stdlib.h | 4 | ||||
-rw-r--r-- | sys/src/ape/lib/ap/gen/mkstemp.c | 25 |
2 files changed, 29 insertions, 0 deletions
diff --git a/sys/include/ape/stdlib.h b/sys/include/ape/stdlib.h index 03fbb88c4..896439723 100644 --- a/sys/include/ape/stdlib.h +++ b/sys/include/ape/stdlib.h @@ -49,6 +49,10 @@ extern int wctomb(char *, wchar_t); extern size_t mbstowcs(wchar_t *, const char *, size_t); extern size_t wcstombs(char *, const wchar_t *, size_t); +#ifdef _POSIX_C_SOURCE +extern int mkstemp(char *template); +#endif + #ifdef __cplusplus } #endif diff --git a/sys/src/ape/lib/ap/gen/mkstemp.c b/sys/src/ape/lib/ap/gen/mkstemp.c new file mode 100644 index 000000000..ef2169b59 --- /dev/null +++ b/sys/src/ape/lib/ap/gen/mkstemp.c @@ -0,0 +1,25 @@ +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +int +mkstemp(char *template) +{ + char *s; + int i, fd; + + s = strdup(template); + if(s == NULL) + return -1; + for(i=0; i<20; i++){ + strcpy(s, template); + mktemp(s); + if((fd = creat(s, 0666)) >= 0){ + strcpy(template, s); + free(s); + return fd; + } + } + free(s); + return -1; +} |