'\" te .\" Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved. .\" Copyright 1989 AT&T .\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved. .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. This notice shall appear on any product containing this material. .TH mktemp 3C "9Jul 2012" "SunOS 5.11" "Standard C Library Functions" .SH NAME mktemp, mkdtemp \- make a unique file name from a template .SH SYNOPSIS .LP .nf #include \fBchar *\fR\fBmktemp\fR(\fBchar *\fR\fItemplate\fR); .fi .LP .nf \fBchar *\fR\fBmkdtemp\fR(\fBchar *\fR\fItemplate\fR); .fi .SH DESCRIPTION .sp .LP The \fBmktemp()\fR function replaces the contents of the string pointed to by \fItemplate\fR with a unique file name, and returns \fItemplate\fR. The string in \fItemplate\fR should look like a file name with six trailing 'X's. The \fBmktemp()\fR function will replace the 'X's with a character string that can be used to create a unique file name. .sp .LP The \fBmkdtemp()\fR function makes the same replacement to the template as in \fBmktemp()\fR and creates the template directory using \fBmkdir\fR(2), passing a \fImode\fR argument of 0700. .SH RETURN VALUES .sp .LP The \fBmktemp()\fR function returns the pointer \fItemplate\fR. If a unique name cannot be created, \fItemplate\fR points to a null string. .sp .LP Upon successful completion, \fBmkdtemp()\fR returns the pointer \fItemplate\fR. If a unique directory cannot be created, \fBmkdtemp()\fR returns a null pointer. .SH ERRORS .sp .LP The \fBmkdtemp()\fR function can set \fBerrno\fR to the same values as \fBlstat\fR(2) and \fBmkdir\fR(2). .SH EXAMPLES .LP \fBExample 1 \fRGenerate a filename. .sp .LP 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. .sp .in +2 .nf #include \&... char *template = "/tmp/fileXXXXXX"; char *ptr; ptr = mktemp(template); .fi .in -2 .SH USAGE .sp .LP 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 \fBtmpfile\fR(3C) and \fBmkstemp\fR(3C) functions avoid this problem and are preferred over this function. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelSafe _ StandardSee \fBstandards\fR(5). .TE .SH SEE ALSO .sp .LP \fBlstat\fR(2), \fBmkdir\fR(2), \fBmkstemp\fR(3C), \fBtmpfile\fR(3C), \fBtmpnam\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)