gtpc2m7l | C/C++ Language Support User's Guide |
This function creates a temporary binary file. It opens the temporary file in wb+ mode. The file is automatically removed when it is closed or when the program ends.
Format
#include <stdio.h> FILE *tmpfile(void);
Normal Return
If successful, this function returns a pointer to the stream associated with the file that is created.
Error Return
If the tmpfile function cannot open the file, it returns a NULL pointer.
The following are the possible values of errno:
FOPEN_MAX streams are currently open in the calling process.
Programming Considerations
Temporary files cannot be created in 1052 or UTIL state.
Examples
The following example creates a temporary file and, if successful, writes the character string, tmpstring, to it. When the program ends, the file is removed.
#include <stdio.h> int main(void) { FILE *stream; char tmpstring[] = "This string will be written."; if((stream = tmpfile( )) == NULL) printf("Cannot make a temporary file\n"); else fprintf(stream, "%s", tmpstring); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.