Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

tmpnam - create base name for temporary file

&pagelevel(4)&pagelevel

Syntax

#include <stdio.h>

char *tmpnam(char *s)

Description tmpnam() generates a string that is a valid and unique file name.

tmpnam() generates a different string each time it is called from the same process, up to
{TMP_MAX} times. If the function is called more than {TMP_MAX} times, previously created
names are reused.

The implementation behaves as if no library functions call the tmpnam() function.

The directory in which temporary files are created, P_tmpdir, is defined in stdio.h as
/var/tmp.

Return val.

Pointer to a string

upon successful completion.

Null pointer

if tmpnam() was called more than {TMP_MAX} times.

If the argument s is a null pointer, tmpnam() places its result in an internal static area and

returns a pointer to that area. Subsequent calls to tmpnam() may modify the same area.

If the argument s is not a null pointer, it is presumed to point to an array of type char with a
minimum length of {L_tmpnam}; tmpnam() writes its result in that array and returns the
argument as its return value.

Notes

If the tmpnam() function is called more than {TMP_MAX}times a single process, the names
created earlier will be reused.

It is the user’s responsibility to delete the file pointed to by *s when it is no longer needed.

Between the time a pathname is created and the file is opened, it is possible for some other
process to create a file with the same name. It may therefore be more practical to use the
tmpfile() function.

Note that this cannot occur if the other process is using tempnam() or mktemp() and if the
pathname is chosen so as to render duplication by other means unlikely.

Files created using tmpnam() and either fopen() or creat() are temporary only in the
sense that they reside in a directory intended for temporary use and have unique names.

The program environment determines tmpnam() is executed for a BS2000 or POSIX file.

See also

fopen(), open(), tempnam(), tmpfile(), unlink(), stdio.h.