|
|
#include <stdlib.h> int mkstemp(char *template);
The string in template should look like a file name with six trailing X characters (XXXXXX); mkstemp replaces each X with a character from the portable file name character set. The characters are chosen such that the resulting name does not duplicate the name of an existing file.
The mkstemp function does not check to determine whether the file name part of template exceeds the maximum allowable file name length.
mkstemp actually changes the template string which you pass; this means that you cannot use the same template string more than once -- you need a fresh template for every unique file you want to open.
When mkstemp is creating a new unique filename it checks for the prior existence of a file with that name. This means that if you are creating more than one unique filename, it is bad practice to use the same root template for multiple invocations of mkstemp.