c Programming/C Reference/stdio.h/tmpfile

< C Programming < C Reference < stdio.h

Template:C Standard library In computing, tmpfile is an ISO C/POSIX function for creating a temporary file, a computer file which ceases to exist when the program, which opened the file, closes it or terminates.[1][2][3]

Usage

Inclusion

C

#include <stdio.h>

C++

#include <cstdio>

Declaration

FILE* tmpfile(void);

Semantics

The function tmpfile reports a pointer to a valid file stream on success; on failure, it returns NULL.[1]

Error conditions

In addition to returning NULL, tmpfile sets errno on failure. The permissible values of errno, if tmpfile fails, are:[1]

Caveats

The tmpfile function is susceptible to a number of security vulnerabilities; use the non-portable mkstemp (UNIX) or tmpfile_s (MSVCRT) functions, instead, to avoid these issues.[4][5]

The implementation of this function in Microsoft C run-time library tries to create the file in the root directory of the current drive and typically fails reporting "Access denied".

See also

References

External links

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.