TMPNAM(3s,L) AIX Technical Reference TMPNAM(3s,L)
-------------------------------------------------------------------------------
tmpnam, tempnam
PURPOSE
Constructs the name for a temporary file.
LIBRARY
Standard I/O Library (libc.a)
SYNTAX
#include <stdio.h>
char *tmpnam (s) char *tempnam (dir, pfx)
char *s; char *dir, *pfx;
DESCRIPTION
The tmpnam and tempnam subroutines generate file names for temporary files.
The tmpnam subroutine generates a file name using the path name defined as
P_tmpdir in the stdio.h header file. If the s parameter is NULL, the tmpnam
subroutine places its result into an internal static area and returns a pointer
to that area. The next call to this subroutine destroys the contents of the
area.
If the s parameter is not NULL, it is assumed to be the address of an array of
at least the number of bytes specified by L_tmpnam. L_tmpnam is a constant
defined in stdio.h. The tmpnam subroutine places its results into that array
and returns the value of the s parameter.
The tempnam subroutine allows you to control the choice of a directory. The
dir parameter points to the path name of the directory in which the file is to
be created. If the dir parameter is NULL or points to a string which is not a
path name for an appropriate directory, the path name defined as P_tmpdir in
the stdio.h header file is used. If that path name is not accessible, /tmp is
used. You can bypass the selection of a path name by providing an environment
variable, TMPDIR, in the user's environment. The value of the TMPDIR variable
is a path name for the desired temporary-file directory. If the TMPDIR
variable is used, both the dir parameter and L_tmpnam are ignored.
The pfx parameter of the tempname subroutine allows you to specify an initial
character sequence with which the file name begins. The pfx parameter can be
Processed November 7, 1990 TMPNAM(3s,L) 1
TMPNAM(3s,L) AIX Technical Reference TMPNAM(3s,L)
NULL, or it can point to a string of up to five characters to be used as the
first few characters of the temporary file name.
The tempnam subroutine uses the malloc subroutine to obtain space for the
constructed file name. The return value is a pointer to this space.
Therefore, the pointer value returned by tempnam can be used as a parameter to
the free subroutine.
If the tempnam subroutine cannot return the expected result for any reason (for
example, if the malloc subroutine fails, or if an appropriate directory cannot
be found), then it returns a NULL pointer.
Warning: The tmpnam and tempnam subroutines generate a different file name
each time they are called. If they are called more than 4,096 times by a
single process, they start recycling previously used names.
File names created using these subroutines reside in a directory intended for
temporary use, and their names are unique. It is your responsibility to use
the open and unlink system calls to create the file and remove it when no
longer needed.
These subroutines use the process ID of the process that invoked them.
Therefore, another process cannot create, open, or close files of the same name
unless it does not use these subroutines and explicitly builds file names using
the current process ID of the process that created the file.
ERROR CONDITIONS
The tempnam and tmpnam subroutines fail if the following is true:
ENOMEM Insufficient storage space is available.
RELATED INFORMATION
In this book: "fopen, freopen, fdopen," "malloc, free, realloc, calloc,
valloc, alloca, mallopt, mallinfo," "mktemp," "open, openx, creat," "tmpfile,"
"unlink, rmslink, remove," and "environment."
Processed November 7, 1990 TMPNAM(3s,L) 2