Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mktemp(3c) [sunos man page]

mktemp(3C)						   Standard C Library Functions 						mktemp(3C)

NAME
mktemp - make a unique file name from a template SYNOPSIS
#include <stdlib.h> char *mktemp(char *template); DESCRIPTION
The mktemp() function replaces the contents of the string pointed to by template with a unique file name, and returns template. The string in template should look like a file name with six trailing 'X's; mktemp() will replace the 'X's with a character string that can be used to create a unique file name. Only 26 unique file names per thread can be created for each unique template. RETURN VALUES
The mktemp() function returns the pointer template. If a unique name cannot be created, template points to a null string. ERRORS
No errors are defined. EXAMPLES
Example 1: Generate a filename. The following example replaces the contents of the "template" string with a 10-character filename beginning with the characters "file" and returns a pointer to the "template" string that contains the new filename. #include <stdlib.h> ... char *template = "/tmp/fileXXXXXX"; char *ptr; ptr = mktemp(template); USAGE
Between the time a pathname is created and the file opened, it is possible for some other process to create a file with the same name. The mkstemp(3C) function avoids this problem and is preferred over this function. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
mkstemp(3C), tmpfile(3C), tmpnam(3C), attributes(5), standards(5) SunOS 5.10 15 Sep 2004 mktemp(3C)

Check Out this Related Man Page

mktemp(3)						     Library Functions Manual							 mktemp(3)

NAME
mktemp, mkstemp - Construct a unique file name LIBRARY
Standard C Library (libc.so, libc.a), System V Compatibility Library (libsys5.a) SYNOPSIS
Standard C Library #include <stdlib.h> int mkstemp( char *template); char *mktemp( char *template); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: mktemp(), mkstemp(): XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to a string to be replaced with a unique file name. The string in the template parameter must be a file name with six trailing Xs. DESCRIPTION
The mktemp() function replaces the contents of the string pointed to by the template parameter with a unique file name. The application must initialize template to be a file name with six trailing Xs; mktemp() replaces the Xs in the template string with a unique file name. Under libc.a, the file name is a unique combination of the thread name and process ID. Under libsys5.a, the file name is created with the getpid function. The mkstemp() function performs the same substitution to the template name and also returns a file descriptor for the file and opens the file with "owner" reading and writing privileges (0600). The function thus prevents any possible race condition between testing whether the file exists and opening it for use. The mkstemp() function is not available under libsys5.a. RETURN VALUES
Upon successful completion, the mktemp() function returns the address of the string pointed to by the template parameter. If the string pointed to by the template parameter contains no Xs, or if the mktemp() function is unable to construct a unique file name, the first character of the template parameter string is replaced with a null character, and a null pointer is returned. Upon successful completion, the mkstemp() function returns an open file descriptor. If the mkstemp() function fails, it returns a value of -1. ERRORS
No errors are defined for this routine. RELATED INFORMATION
Functions: tmpfile(3), tmpnam(3), getpid(2) Standards: standards(5) delim off mktemp(3)
Man Page