tmpfile(), tmpfile64()

QNX SDP8.0C Library ReferenceAPIDeveloper

Create a temporary file

Synopsis:

#include <stdio.h>

FILE* tmpfile( void );

FILE* tmpfile64( void );

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The tmpfile() and tmpfile64() functions create a temporary file and open a corresponding FILE stream.

Note:
The tmpfile64() function is a large-file support version of tmpfile() provided for backwards compatibility. If you're using large-file support functions and data types, you should define _LARGEFILE64_SOURCE with a value of 1 to ensure they appear in the name space. For more information, see Classification in What's in a Function Description?.

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.

Note:
When a stream is opened in update mode, both reading and writing may be performed. However, writing may not be followed by reading without an intervening call to fflush(), or to a file-positioning function (fseek(), fsetpos(), rewind()). Similarly, reading may not be followed by writing without an intervening call to a file-positioning function, unless the read resulted in end-of-file.

Returns:

A pointer to the stream of the temporary file, or NULL if an error occurs (errno is set).

Errors:

EACCES
The calling process doesn't have permission to create the temporary file.
EINTR
A signal was caught during the execution of tmpfile().
EMFILE
All file descriptors available to the process are currently open.
ENFILE
The system already has the maximum number of files open.
ENOMEM
Insufficient memory is available.
ENOSPC
The directory or filesystem that would contain the new file cannot be expanded.
EROFS
The filesystem for the temporary file is read-only.

Examples:

#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;
}

Classification:

tmpfile() is ANSI, POSIX 1003.1; tmpfile64() is Large-file support

Safety:
Cancellation pointYes
Signal handlerNo
ThreadYes
Page updated: