1 .\" Copyright 2014 Garrett D'Amore <garrett@damore.org> 2 .\" Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. 3 .\" Copyright 1989 AT&T 4 .\" Portions Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved. 5 .\" 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 6 .\" http://www.opengroup.org/bookstore/. 7 .\" 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. 8 .\" This notice shall appear on any product containing this material. 9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. 10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. 11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 12 .Dd "Jul 21, 2014" 13 .Dt MKTEMP 3C 14 .Os 15 .Sh NAME 16 .Nm mktemp 17 .Nd make a unique file name from a template 18 .Sh SYNOPSIS 19 .In stdlib.h 20 .Ft "char *" 21 .Fn mktemp "char *template" 22 .Sh DESCRIPTION 23 The 24 .Fn mktemp 25 function replaces the contents of the string pointed to by 26 .Fa template 27 with a unique file name, and returns 28 .Fa template . 29 The string in 30 .Fa template 31 should look like a file name with six trailing 32 .So X Sc Ns s ; 33 .Fn mktemp 34 will replace the 35 .So X Sc Ns s 36 with a character string that can be used 37 to create a unique file name. Only 26 unique file names per thread can be 38 created for each unique 39 .Fa template . 40 .Sh RETURN VALUES 41 The 42 .Fn mktemp 43 function returns a pointer to the 44 .Fa template 45 on success and 46 .Dv NULL 47 if unique name cannot be created. 48 .Sh EXAMPLES 49 .Ss Example 1 Generate a filename. 50 The following example replaces the contents of the "template" string with a 51 10-character filename beginning with the characters "file" and returns a 52 pointer to the "template" string that contains the new filename. 53 .Bd -literal -offset indent 54 #include <stdlib.h> 55 \&... 56 char template[] = "/tmp/fileXXXXXX"; 57 char *ptr; 58 ptr = mktemp(template); 59 .Ed 60 .Sh ERRORS 61 No errors are defined. 62 .Sh SECURITY 63 Between the time a pathname is created and the file opened, it is possible for 64 some other process to create a file with the same name. The 65 .Xr mkstemp 3C 66 function avoids this problem and is preferred over this function. 67 .Sh INTERFACE STABILITY 68 .Sy Obsolete Standard . 69 .Sh MT-LEVEL 70 .Sy Safe . 71 .Sh SEE ALSO 72 .Xr mkstemp 3C , 73 .Xr tmpfile 3C , 74 .Xr tmpnam 3C , 75 .Xr standards 5 76 .Sh STANDARDS 77 The 78 .Fn mktemp 79 function was introduced in 80 .At v7 81 and subsequently standardized in 82 .St -xpg4.2 . 83 It was obsoleted in 84 .St -p1003.1-2001 , 85 and removed from 86 .St -p1003.1-2008 .