]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/mktemp.3
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[thirdparty/man-pages.git] / man3 / mktemp.3
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 filename
35 .SH SYNOPSIS
36 .nf
37 .B #include <stdlib.h>
38 .sp
39 .BI "char *mktemp(char *" template );
40 .fi
41 .SH DESCRIPTION
42 The \fBmktemp\fP() function generates a unique temporary filename
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.
46 Since it will be modified,
47 .I template
48 must not be a string constant, but should be declared as a character array.
49 .SH "RETURN VALUE"
50 The \fBmktemp\fP() function returns NULL on error (\fItemplate\fP did not
51 end in XXXXXX) and \fItemplate\fP otherwise.
52 If the call was successful, the last six bytes of \fItemplate\fP will
53 have been modified in such a way that the resulting name is unique
54 (does not exist already).
55 If the call was unsuccessful, \fItemplate\fP
56 is made an empty string.
57 .SH ERRORS
58 .TP
59 .B EINVAL
60 The last six characters of \fItemplate\fP were not XXXXXX.
61 .SH "CONFORMING TO"
62 4.3BSD, POSIX.1-2001.
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
70 Never use \fBmktemp\fP().
71 Some implementations follow 4.3BSD
72 and replace XXXXXX by the current process ID and a single letter,
73 so that at most 26 different names can be returned.
74 Since on the one hand the names are easy to guess, and on the other
75 hand there is a race between testing whether the name exists and
76 opening the file, every use of \fBmktemp\fP() is a security risk.
77 The race is avoided by
78 .BR mkstemp (3).
79 .SH "SEE ALSO"
80 .BR mkstemp (3),
81 .BR tempnam (3),
82 .BR tmpfile (3),
83 .BR tmpnam (3)