tmpfile()

NAME

tmpfile(), tmpnam() - temporary file routines

SYNOPSIS

#include <stdio.h>

FILE * tmpfile (void) char * tmpnam (char *str)

DESCRIPTION

The tmpfile(3) function returns a pointer to a stream associated with a file descriptor returned by the routine mkstemp(3). The created file is unlinked before tmpfile(3) returns, causing the file to be automatically deleted when the last reference to it is closed. The file is opened with the access value w+.

The tmpnam(3) function returns a pointer to a file name which did not reference an existing file at some indeterminate point in the past. If the argument s is non-NULL, the file name is copied to the buffer it references. Otherwise, the file name is copied to a static buffer. In either case, tmpnam(3) returns a pointer to the file name.

The buffer referenced by s is expected to be at least {L_tmpnam} bytes in length. {L_tmpnam} is defined in the include file <stdio.h>.

The environment variable TMPDIR (if set), the argument tmpdir (if non-NULL), and the directory /tmp are tried, in that order, as directories in which to store the temporary file.

RETURN VALUES

The tmpfile(3) function returns a pointer to an open file stream on success, and a NULL pointer on error.

The tmpnam(3) returns a pointer to a file name on success, and a NULL pointer on error.

ERRORS

The tmpfile(3) function may fail and set the global variable errno for any of the errors specified for the library functions fdopen(3) or mkstemp(3).

The tmpnam(3) function may fail and set errno for any of the errors specified for the library function mktemp(3).

The tempnam(3) function may fail and set errno for any of the errors specified for the library functions malloc(3) or mktemp(3).

SEE ALSO

mktemp(3)

tempnam(3)