Your Browser is not longer supported
Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...
{{viewport.spaceProperty.prod}}
mktemp - make unique temporary file name (extension)
&pagelevel(4)&pagelevel
Syntax | #include <stdlib.h> char *mktemp(char *template); |
Description | mktemp() replaces the contents of the string pointed to by template with a unique file name and returns the address of template. The string to which template points should contain a file name followed by six Xs. mktemp() replaces these Xs with a letter and the current process ID to create a unique file name.
The letter is chosen so that the new file name will be unique, i.e. will not match any existing file name. BS2000
mktemp() creates a unique file name for a temporary SAM file. The name must consist of at least 8 characters and is constructed as follows: The first three characters are replaced by "#T.". The fourth character is replaced by a character that varies for each mktemp call (letters A - Z, digits 0 - 9). The last four characters are replaced by the TSN of the current task (since LOGON). Characters between the first and last four characters remain unchanged.
For example, if the value of template is "XXXX.ABC.XXXX" and the TSN of the current task is 6082, the temporary name generated by mktemp() at the first call will be: #T.A.ABC.6082 (End) |
Return val. | Pointer to a string containing the new name if successful. Pointer to an empty string if no unique name can be created, e.g. because no more letters are free. |
Notes | In the time between the creation of the file name and the opening of the file, another process can create a file with the same name. To avoid this problem, use the mkstemp() function. For reasons of portability to implementations which comply with earlier versions of the X/Open standard, the tmpnam() function is recommended for creating a unique file name. mktemp() can create a maximum of 26 unique file names per process for each unique template.
BS2000 Temporary files are automatically deleted on termination of a task (LOGOFF). However, if the standard prefix (#) for temporary files was changed at system generation, the files are retained. (End) The program environment determines whether a BS2000 or POSIX file is created. |
See also | tmpfile() , stdlib.h .
|