summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2019-09-09 15:58:39 +0100
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2019-09-09 15:58:39 +0100
commite0720a48b0ce9db78aa1e048e4e2d1d5cfae41db (patch)
tree149cee510324f36fe9c6d2ec15fa68ac83cb8bfb
parent662fd71e115b1cbd35233f2d64f7828bb9bd3f59 (diff)
downloadplan9front-e0720a48b0ce9db78aa1e048e4e2d1d5cfae41db.tar.xz
Add mkstemp to stdlib.h
q
-rw-r--r--sys/include/ape/stdlib.h4
-rw-r--r--sys/src/ape/lib/ap/gen/mkstemp.c25
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;
+}