ref: e0720a48b0ce9db78aa1e048e4e2d1d5cfae41db
parent: 662fd71e115b1cbd35233f2d64f7828bb9bd3f59
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Sep 9 11:58:39 EDT 2019
Add mkstemp to stdlib.h q
--- a/sys/include/ape/stdlib.h
+++ b/sys/include/ape/stdlib.h
@@ -49,6 +49,10 @@
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
--- /dev/null
+++ b/sys/src/ape/lib/ap/gen/mkstemp.c
@@ -1,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;
+}