Add mkstemp to stdlib.h
q
This commit is contained in:
parent
662fd71e11
commit
e0720a48b0
2 changed files with 29 additions and 0 deletions
|
@ -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
|
||||
|
|
25
sys/src/ape/lib/ap/gen/mkstemp.c
Normal file
25
sys/src/ape/lib/ap/gen/mkstemp.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue