]>
Commit | Line | Data |
---|---|---|
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 | |
34 | mktemp \- 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 | 42 | The \fBmktemp\fP() function generates a unique temporary file name |
fea681da MK |
43 | from \fItemplate\fP. The last six characters of \fItemplate\fP must |
44 | be XXXXXX and these are replaced with a string that makes the | |
45 | filename unique. Since it will be modified, | |
46 | .I template | |
47 | must not be a string constant, but should be declared as a character array. | |
48 | .SH "RETURN VALUE" | |
63aa9df0 | 49 | The \fBmktemp\fP() function returns NULL on error (\fItemplate\fP did not |
fea681da MK |
50 | end in XXXXXX) and \fItemplate\fP otherwise. |
51 | If the call was successful, the last six bytes of \fItemplate\fP will | |
52 | have been modified in such a way that the resulting name is unique | |
53 | (does not exist already). If the call was unsuccessful, \fItemplate\fP | |
54 | is made an empty string. | |
55 | ||
56 | .SH ERRORS | |
57 | .TP | |
58 | .B EINVAL | |
59 | The last six characters of \fItemplate\fP were not XXXXXX. | |
60 | .SH "CONFORMING TO" | |
b14d4aa5 | 61 | 4.3BSD. POSIX dictates |
fea681da MK |
62 | .BR tmpnam (3). |
63 | .SH NOTE | |
64 | The prototype is in | |
65 | .I <unistd.h> | |
66 | for libc4, libc5, glibc1; glibc2 follows the Single Unix Specification | |
67 | and has the prototype in | |
68 | .IR <stdlib.h> . | |
69 | .SH BUGS | |
63aa9df0 | 70 | Never use \fBmktemp\fP(). Some implementations follow 4.3BSD |
357cf3fe | 71 | and replace XXXXXX by the current process ID and a single letter, |
fea681da MK |
72 | so that at most 26 different names can be returned. |
73 | Since on the one hand the names are easy to guess, and on the other | |
74 | hand there is a race between testing whether the name exists and | |
63aa9df0 | 75 | opening the file, every use of \fBmktemp\fP() is a security risk. |
fea681da MK |
76 | The 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) |