mirror of
https://github.com/cahirwpz/libnix.git
synced 2025-12-08 14:58:56 +00:00
30 lines
426 B
C
30 lines
426 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <sys/syslimits.h>
|
|
|
|
/* NOTE: NOT thread-safe */
|
|
FILE *tmpfile(void)
|
|
{
|
|
char *name = malloc(PATH_MAX);
|
|
FILE *file;
|
|
|
|
if (name == NULL)
|
|
goto error;
|
|
|
|
if (tmpnam(name) == NULL) {
|
|
goto error;
|
|
}
|
|
|
|
file = fopen(name,"w+b");
|
|
if (file == NULL)
|
|
goto error;
|
|
|
|
file->name = name;
|
|
return file;
|
|
error:
|
|
if (name != NULL)
|
|
free(name);
|
|
|
|
return NULL;
|
|
}
|