MKTEMP(3C) MKTEMP(3C) NAME mktemp, mkstemp - make a unique file name SYNOPSIS #include <stdio.h> char *mktemp (char *template); int mkstemp(char *template); DESCRIPTION Mktemp replaces the contents of the string pointed to by template by a unique file name, and returns the address of template. The string in template should look like a file name with six trailing Xs; mktemp will replace the Xs with a string that can be used to create a unique file name. Mkstemp makes the same replacement to the template but returns a file descriptor for the template file open for reading and writing. Mkstemp avoids the race between testing whether the file exists and opening it for use. The mkstemp routine is from the 4.3BSD standard C library. SEE ALSO getpid(2), tmpfile(3S), tmpnam(3S). DIAGNOSTICS Mktemp will assign a zero to the first character of template if it cannot create a unique name, returning the empty string. Mkstemp returns an open file descriptor upon success. It returns -1 if no suitable file could be created. CAVEAT Mktemp makes 26 attempts to generate a filename which is not currently in use from a given template. Since the filename generated uses the process ID as a base, it is highly unlikely that these names will conflict with those generated by another process. Variation in the contents of the actual string given to mktemp, as well as the number of times mktemp is called, will determine the likelihood of successfully generating a unique name. Page 1