Visit Our UNIX and Linux User Community

Linux and UNIX Man Pages

Test Your Knowledge in Computers #157
Difficulty: Easy
The US Department of Defense declared TCP/IP as the standard for all military computer networking in March 1982,
True or False?
Linux & Unix Commands - Search Man Pages

mktemp(3) [bsd man page]

MKTEMP(3)						     Library Functions Manual							 MKTEMP(3)

mktemp - make a unique file name SYNOPSIS
char *mktemp(template) char *template; mkstemp(template) char *template; DESCRIPTION
Mktemp creates a unique file name and returns the address of the template. The template should contain a file name with trailing X's, nor- mally something like /tmp/tempXXXXXX. The X's are replaced by the current process number and/or a unique letter combination. Mkstemp makes the same replacement to the template but opens the template file and returns a file descriptor open for reading and writing. Mkstemp avoids the race between testing whether the file exists and opening it for use. The number of file name combinations mktemp and mkstemp will try depends on the number of X's placed on the end of the template; six X's will result in them trying roughly 26 ** 6 combinations. SEE ALSO
access(2), getpid(2), open(2) DIAGNOSTICS
Mktemp returns NULL on failure, mkstemp returns -1 if no suitable file could be created. 7th Edition April 10, 1987 MKTEMP(3)

Check Out this Related Man Page

mktemp(3)						     Library Functions Manual							 mktemp(3)

mktemp, mkstemp - Construct a unique file name LIBRARY
Standard C Library (, 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)

Featured Tech Videos