Add mkstemp to stdlib.h

q
This commit is contained in:
Roberto E. Vargas Caballero 2019-09-09 15:58:39 +01:00
parent 662fd71e11
commit e0720a48b0
2 changed files with 29 additions and 0 deletions

View file

@ -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

View 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;
}