Create a temporary file
#include <stdio.h> FILE* tmpfile( void ); FILE* tmpfile64( void );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The tmpfile() and tmpfile64() functions create a temporary file and open a corresponding FILE stream. The tmpfile64() function is a large-file support version of tmpfile().
The file is automatically removed when it's closed or when the program terminates. The file is opened in update mode (as in fopen()'s w+ mode).
If the process is killed between file creation and unlinking, a permanent file may be left behind.
A pointer to the stream of the temporary file, or NULL if an error occurs (errno is set).
#include <stdio.h> #include <stdlib.h> static FILE *TempFile; int main( void ) { TempFile = tmpfile(); … fclose( TempFile ); /* The temporary file will be removed when we exit. */ return EXIT_SUCCESS; }
tmpfile() is ANSI, POSIX 1003.1; tmpfile64() is Large-file support
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |