]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mkstemp.3
Convert to American spelling conventions
[thirdparty/man-pages.git] / man3 / mkstemp.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\" Modified Sat Jul 24 18:48:48 1993 by Rik Faith (faith@cs.unc.edu)
28 .\" Modified 980310, aeb
29 .\" Modified 990328, aeb
30 .\"
31 .TH MKSTEMP 3 2001-12-23 "GNU" "Linux Programmer's Manual"
32 .SH NAME
33 mkstemp \- create a unique temporary file
34 .SH SYNOPSIS
35 .nf
36 .B #include <stdlib.h>
37 .sp
38 .BI "int mkstemp(char *" template );
39 .fi
40 .SH DESCRIPTION
41 The
42 .BR mkstemp ()
43 function generates a unique temporary filename
44 from \fItemplate\fP.
45 The last six characters of \fItemplate\fP must
46 be XXXXXX and these are replaced with a string that makes the
47 filename unique.
48 The file is then created with mode read/write and
49 permissions 0666 (glibc 2.0.6 and earlier), 0600 (glibc 2.0.7 and later).
50 Since it will be modified,
51 .I template
52 must not be a string constant, but should be declared as a character array.
53 The file is opened with the
54 .BR open (2)
55 .B O_EXCL
56 flag, guaranteeing that when
57 .BR mkstemp ()
58 returns successfully we are the only user.
59 .SH "RETURN VALUE"
60 On success, the
61 .BR mkstemp ()
62 function returns the file descriptor
63 of the temporary file.
64 On error, \-1 is returned, and
65 .I errno
66 is set appropriately.
67 .SH ERRORS
68 .TP
69 .B EEXIST
70 Could not create a unique temporary filename.
71 Now the contents of \fItemplate\fP are undefined.
72 .TP
73 .B EINVAL
74 The last six characters of \fItemplate\fP were not XXXXXX.
75 Now \fItemplate\fP is unchanged.
76 .SH "CONFORMING TO"
77 4.3BSD, POSIX.1-2001
78 .SH NOTES
79 The old behavior (creating a file with mode 0666) may be
80 a security risk, especially since other Unix flavors use 0600,
81 and somebody might overlook this detail when porting programs.
82
83 More generally, the POSIX specification does not say anything
84 about file modes, so the application should make sure its umask
85 is set appropriately before calling
86 .BR mkstemp ().
87
88 The prototype is in
89 .I <unistd.h>
90 for libc4, libc5, glibc1; glibc2 follows POSIX.1 and has the prototype in
91 .IR <stdlib.h> .
92 .SH "SEE ALSO"
93 .BR mkdtemp (3),
94 .BR mktemp (3),
95 .BR tempnam (3),
96 .BR tmpfile (3),
97 .BR tmpnam (3)