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

&pagelevel(4)&pagelevel

Definition   

#include <stdio.h>

char *tmpnam(char *s);

tmpnam generates a unique file name from the TSN number of the current task, an internal identifier, the time, the date, and a number of up to four digits. Each time tmpnam is called this number changes; so, too, does the time each time a second elapses. This ensures that the name is always different from the names of existing files.
tmpnam can be called at most TMP_MAX times.

The file name can then be used for creating any new file.

Return val.

Pointer to the generated name



If s is a NULL pointer, tmpnam writes the result to an internal C memory area which is overwritten with each call.
If s is not a NULL pointer tmpnam writes the result to the result string s. Sufficient memory to take at least L_tmpnam characters must be made available for s. L_tmpnam is defined in <stdio.h>.


0    

if tmpnam has been called more than TMP_MAX times.

Notes

tmpnam generates a maximum of TMP_MAX names. TMP_MAX is defined in the include file <stdio.h>.

Files opened with names generated by tmpnam are not automatically deleted at the end of the program or task. The files must be explicitly deleted (e.g. with remove).

Example

#include <stdio.h>
int main(void)
{
 FILE *fp1;
 FILE *fp2;
 char nam1[L_tmpnam];
 char nam2[L_tmpnam];
 tmpnam(nam1);
 printf("Name1: %s\n", nam1); /* Name1: S.C.UNQ.1RCP.00.13211.2709199.0000 */
 fp1 = fopen(nam1, "w+r");
 tmpnam(nam2);
 printf("Name2: %s\n", nam2); /* Name2: S.C.UNQ.1RCP.00.13211.2709199.0001 */
 fp2 = fopen(nam2, "w+r");
 fclose(fp1);
 fclose(fp2);
 remove(nam1);
 remove(nam2);
}

See also

tmpfile, tmpfile64, mktemp, remove