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 - Generate a unique temporary file name

&pagelevel(4)&pagelevel

Definition   

#include <stdio.h>

char *mktemp(char *model);

mktemp generates unique names for temporary SAM files from a string model, which must contain at least 8 characters. The name is composed from the characters in model as follows:

  • The first three characters are replaced by "#T.".

  • The fourth character is replaced by a character which 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 contents of model were "XXXX.ABC.XXXX" and the TSN of the running task were 6082, the temporary name generated by mktemp at the first call would be:

#T.A.ABC.6082

Return val.

Pointer to the result string containing the new name


if successful.

NULL pointer

if an error occurred, e.g. because model contains less than 8 characters or because the maximum permissible number (36) of mktemp calls has been exceeded (see notes for further information).

Notes

Since the letters A-Z and the digits 0-9 are used for the formation of a unique name, the number of mktemp calls is limited to 36 per program run.

Temporary files are automatically deleted on termination of a task (LOGOFF). However, the files are retained if the standard prefix (#) for temporary files was changed during system generation.

Example

The following program generates three unique temporary file names and opens the files for writing and reading.

#include <stdio.h>
FILE *fp1, *fp2, *fp3;
char s[] = "XXXX.temp.XXXX";
int main(void)
{ 
   mktemp(s);
   fp1 = fopen(s,"w+r");
   printf("%s\n",s);              /* generated name: #T.A.TEMP.6082 */
   mktemp(s);
   fp2 = fopen (s,"w+r");
   printf("%s\n",s);              /* generated name: #T.B.TEMP.6082 */
   mktemp(s);
   fp3 = fopen (s,"w+r");
   printf("%s\n",s);              /* generated name: #T.C.TEMP.6082 */
   return 0;
}