1 '\" te
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 .TH MKTEMP 3C "Sep 15, 2004"
13 .SH NAME
14 mktemp \- make a unique file name from a template
15 .SH SYNOPSIS
16 .LP
17 .nf
18 #include <stdlib.h>
19
20 \fBchar *\fR\fBmktemp\fR(\fBchar *\fR\fItemplate\fR);
21 .fi
22
23 .SH DESCRIPTION
24 .sp
25 .LP
26 The \fBmktemp()\fR function replaces the contents of the string pointed to by
27 \fItemplate\fR with a unique file name, and returns \fItemplate\fR. The string
28 in \fItemplate\fR should look like a file name with six trailing 'X's;
29 \fBmktemp()\fR will replace the 'X's with a character string that can be used
30 to create a unique file name. Only 26 unique file names per thread can be
31 created for each unique \fItemplate\fR.
32 .SH RETURN VALUES
33 .sp
34 .LP
35 The \fBmktemp()\fR function returns a pointer to the \fItemplate\fR on success
36 and \fBNULL\fR if unique name cannot be created.
37 .SH ERRORS
38 .sp
39 .LP
40 No errors are defined.
41 .SH EXAMPLES
42 .LP
43 \fBExample 1 \fRGenerate a filename.
44 .sp
45 .LP
46 The following example replaces the contents of the "template" string with a
47 10-character filename beginning with the characters "file" and returns a
48 pointer to the "template" string that contains the new filename.
49
50 .sp
51 .in +2
52 .nf
53 #include <stdlib.h>
54 \&...
55 char template[] = "/tmp/fileXXXXXX";
56 char *ptr;
57 ptr = mktemp(template);
58 .fi
59 .in -2
60
61 .SH USAGE
62 .sp
63 .LP
64 Between the time a pathname is created and the file opened, it is possible for
65 some other process to create a file with the same name. The \fBmkstemp\fR(3C)
66 function avoids this problem and is preferred over this function.
67 .SH ATTRIBUTES
68 .sp
69 .LP
70 See \fBattributes\fR(5) for descriptions of the following attributes:
71 .sp
72
73 .sp
74 .TS
75 box;
76 c | c
77 l | l .
78 ATTRIBUTE TYPE ATTRIBUTE VALUE
79 _
80 Interface Stability Standard
81 _
82 MT-Level Safe
83 .TE
84
85 .SH SEE ALSO
86 .sp
87 .LP
88 \fBmkstemp\fR(3C), \fBtmpfile\fR(3C), \fBtmpnam\fR(3C), \fBattributes\fR(5),
89 \fBstandards\fR(5)
|
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 .
|