]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mktemp.3
Minor wording fix.
[thirdparty/man-pages.git] / man3 / mktemp.3
CommitLineData
fea681da
MK
1.\" Copyright (C) 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:06 1993 by Rik Faith (faith@cs.unc.edu)
28.\" Modified Fri Jun 23 01:26:34 1995 by Andries Brouwer (aeb@cwi.nl)
29.\" (prompted by Scott Burkett <scottb@IntNet.net>)
30.\" Modified Sun Mar 28 23:44:38 1999 by Andries Brouwer (aeb@cwi.nl)
31.\"
32.TH MKTEMP 3 1993-04-03 "GNU" "Linux Programmer's Manual"
33.SH NAME
34mktemp \- make a unique temporary file name
35.SH SYNOPSIS
36.nf
37.B #include <stdlib.h>
38.sp
39.BI "char *mktemp(char *" template );
40.fi
41.SH DESCRIPTION
63aa9df0 42The \fBmktemp\fP() function generates a unique temporary file name
fea681da
MK
43from \fItemplate\fP. The last six characters of \fItemplate\fP must
44be XXXXXX and these are replaced with a string that makes the
45filename unique. Since it will be modified,
46.I template
47must not be a string constant, but should be declared as a character array.
48.SH "RETURN VALUE"
63aa9df0 49The \fBmktemp\fP() function returns NULL on error (\fItemplate\fP did not
fea681da
MK
50end in XXXXXX) and \fItemplate\fP otherwise.
51If the call was successful, the last six bytes of \fItemplate\fP will
52have been modified in such a way that the resulting name is unique
53(does not exist already). If the call was unsuccessful, \fItemplate\fP
54is made an empty string.
55
56.SH ERRORS
57.TP
58.B EINVAL
59The last six characters of \fItemplate\fP were not XXXXXX.
60.SH "CONFORMING TO"
b14d4aa5 614.3BSD. POSIX dictates
fea681da
MK
62.BR tmpnam (3).
63.SH NOTE
64The prototype is in
65.I <unistd.h>
66for libc4, libc5, glibc1; glibc2 follows the Single Unix Specification
67and has the prototype in
68.IR <stdlib.h> .
69.SH BUGS
63aa9df0 70Never use \fBmktemp\fP(). Some implementations follow 4.3BSD
357cf3fe 71and replace XXXXXX by the current process ID and a single letter,
fea681da
MK
72so that at most 26 different names can be returned.
73Since on the one hand the names are easy to guess, and on the other
74hand there is a race between testing whether the name exists and
63aa9df0 75opening the file, every use of \fBmktemp\fP() is a security risk.
fea681da
MK
76The race is avoided by
77.BR mkstemp (3).
78.SH "SEE ALSO"
79.BR mkstemp (3),
80.BR tempnam (3),
81.BR tmpfile (3),
82.BR tmpnam (3)