Constructs the name for a temporary file.
#include <stdio.h>
char *tmpnam ( String)
char *String;
char *tempnam ( Directory, FileXPointer)
const char *Directory, *FileXPointer;
Attention: The tmpnam and tempnam subroutines generate a different file name each time they are called. If called more than 16,384 (TMP_MAX) times by a single process, these subroutines recycle previously used names.
The tmpnam and the 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 file.
Files created using the tmpnam subroutine reside in a directory intended for temporary use. The file names are unique. The application must create and remove the file.
The tempnam subroutine enables you to define the directory. The Directory parameter points to the name of the directory in which the file is to be created. If the Directory parameter is a null pointer or points to a string that is not a name for a directory, the path prefix defined as P_tmpdir in the stdio.h file is used. For an application that has temporary files with initial letter sequences, use the FileXPointer parameter to define the sequence. The FileXPointer parameter (a null pointer or a string of up to 5 bytes) is used as the beginning of the file name.
Between the time a file name is created and the file is opened, another process can create a file with the same name. Name duplication is unlikely if the other process uses these subroutines or the mktemp subroutine, and if the file names are chosen to avoid duplication by other means.
Upon completion, the tempnam subroutine allocates space for the string using the malloc subroutine, puts the generated path name in that space, and returns a pointer to the space. Otherwise, it returns a null pointer and sets the errno global variable to indicate the error. The pointer returned by tempnam may be used in the free subroutine when the space is no longer needed.
The tempnam subroutine
returns the following error code if unsuccessful:
ENOMEM | Insufficient storage space is available. |
ENINVAL | Indicates an invalid string value. |
These subroutines are part of Base Operating System (BOS) Runtime.
The fopen, freopen, fdopen subroutine, malloc, free, realloc, calloc, mallopt, mallinfo, or alloca subroutine, mktemp or mkstemp subroutine, openx, open, creat subroutine, tmpfile (tmpfile Subroutine) subroutine, unlink (unlink Subroutine) subroutine.
The environment file.
Files, Directories, and File Systems for Programmers in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.
Input and Output Handling Programmer's Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.