libite
Functions
tempfile.c File Reference
#include <errno.h>
#include <paths.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
Include dependency graph for tempfile.c:

Functions

FILE * tempfile (void)
 A secure tmpfile() replacement. More...
 

Detailed Description

Author
Joachim Wiberg
Date
2015-2021

Function Documentation

◆ tempfile()

FILE* tempfile ( void  )

A secure tmpfile() replacement.

This is the secure replacement for tmpfile() that does not exist in GLIBC. It uses the Linux specific O_TMPFILE and O_EXCL to hide the filename. When the FILE is fclose()'ed, the file contents is lost. The file is hidden in the _PATH_TMP ("/tmp") directory in the system.

This function requires Linux 3.11, or later, due to O_TMPFILE. Not all file systems support hidden inodes, in which case this function defaults to call tmpfile() as a fallback.

Returns
An open FILE pointer, or NULL on error.