teach manpages about largefile's demise
[unleashed.git] / share / man / man3c / mkstemp.3c
blobdde26c5fa3701823eaa0f41f2fecd6dc3fa75e15
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
44 .\" Portions Copyright (c) 2006, Sun Microsystems, Inc.  All Rights Reserved.
45 .\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
46 .\"
47 .TH MKSTEMP 3C "Apr 19, 2013"
48 .SH NAME
49 mkstemp, mkstemps, mkostemp, mkostemps, mkdtemp \- make a unique file name from a template and open
50 the file
51 .SH SYNOPSIS
52 .LP
53 .nf
54 #include <stdlib.h>
56 \fBint\fR \fBmkstemp\fR(\fBchar *\fR\fItemplate\fR);
57 .fi
59 .LP
60 .nf
61 \fBint\fR \fBmkostemp\fR(\fBchar *\fR\fItemplate\fR, \fBint\fR \fIflags\fR);
62 .fi
64 .LP
65 .nf
66 \fBint\fR \fBmkstemps\fR(\fBchar *\fR\fItemplate\fR, \fBint\fR \fIslen\fR);
67 .fi
69 .LP
70 .nf
71 \fBint\fR \fBmkostemps\fR(\fBchar *\fR\fItemplate\fR, \fBint\fR \fIslen\fR, \fBint\fR \fIflags\fR);
72 .fi
74 .LP
75 .nf
76 \fBchar *\fR\fBmkdtemp\fR(\fBchar *\fR\fItemplate\fR);
77 .fi
79 .SH DESCRIPTION
80 .sp
81 .LP
82 The \fBmkstemp()\fR function replaces the contents of the string pointed to by
83 \fItemplate\fR by a unique file name, and returns a file descriptor for the
84 file open for reading and writing. The function thus prevents any possible race
85 condition between testing whether the file exists and opening it for use. The
86 string in \fItemplate\fR should look like a file name with six trailing 'X's;
87 \fBmkstemp()\fR replaces each 'X' with a character from the portable file name
88 character set. The characters are chosen such that the resulting name does not
89 duplicate the name of an existing file.
90 .sp
91 .LP
92 The \fBmkstemps()\fR function behaves the same as \fBmkstemp()\fR, except it
93 permits a suffix to exist in the template. The template should be of the form
94 /\fBtmp\fR/\fBtmp\fR\fIXXXXXX\fR\fIsuffix\fR. The \fIslen\fR parameter
95 specifies the length of the suffix string.
96 .sp
97 .LP
98 The \fBmkostemp()\fR and \fBmkostemps\fR are like their \fBmkstemp()\fR and
99 \fBmkstemps()\fR couterparts except that the \fIflags\fR argument is present
100 and used to supplement (as a bitwise inclusive-OR) flags to internal
101 \fBopen()\fR calls.  (e.g. \fBO_SYNC\fR, \fBO_APPEND\fR, and \fBO_CLOEXEC\fR).
104 The \fBmkdtemp()\fR function makes the same replacement to the template as in
105 \fBmktemp\fR(3C) and creates the template directory using \fBmkdir\fR(2),
106 passing a \fImode\fR argument of 0700.
107 .SH RETURN VALUES
110 Upon successful completion, \fBmkstemp()\fR returns an open file descriptor.
111 Otherwise \(mi1 is returned if no suitable file could be created.
112 .SH ERRORS
115 The \fBmkstemp()\fR, \fBmkstemps()\fR, and \fBmkdtemp()\fR functions can set
116 \fBerrno\fR to the same values as \fBlstat\fR(2).
119 The \fBmkstemp()\fR and \fBmkstemps()\fR functions can set \fBerrno\fR to the
120 same values as \fBopen\fR(2).
123 The \fBmkdtemp()\fR function can set \fBerrno\fR to the same values as
124 \fBmkdir\fR(2).
125 .SH USAGE
128 It is possible to run out of letters.
131 The \fBmkstemp()\fR function does not check to determine whether the file name
132 part of \fItemplate\fR exceeds the maximum allowable file name length.
135 The \fBtmpfile\fR(3C) function is preferred over this function.
138 The \fBmkstemp()\fR function is frequently used to create a temporary file that
139 will be removed by the application before the application terminates.
140 .SH ATTRIBUTES
143 See \fBattributes\fR(5) for descriptions of the following attributes:
148 box;
149 l | l
150 l | l .
151 ATTRIBUTE TYPE  ATTRIBUTE VALUE
153 Interface Stability     See below.
158 The \fBmkstemp()\fR function is Standard. The \fBmkstemps()\fR and
159 \fBmkdtemp()\fR functions are Stable.
160 .SH SEE ALSO
163 \fBgetpid\fR(2), \fBlstat\fR(2), \fBmkdir\fR(2), \fBopen\fR(2),
164 \fBtmpfile\fR(3C), \fBmktemp\fR(3C), \fBattributes\fR(5),
165 \fBstandards\fR(5)