OSDN Git Service

(split) LDP: Change Makefile to stamp-based compilation
[linuxjm/LDP_man-pages.git] / original / man3 / tmpnam.3
1 .\" Copyright (c) 1999 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" 2003-11-15, aeb, added tmpnam_r
26 .\"
27 .TH TMPNAM 3  2010-09-10 "" "Linux Programmer's Manual"
28 .SH NAME
29 tmpnam, tmpnam_r \- create a name for a temporary file
30 .SH SYNOPSIS
31 .nf
32 .B #include <stdio.h>
33 .sp
34 .BI "char *tmpnam(char *" s );
35 .fi
36 .SH DESCRIPTION
37 The
38 .BR tmpnam ()
39 function returns a pointer to a string that is a valid filename,
40 and such that a file with this name did not exist at some point
41 in time, so that naive programmers may think it
42 a suitable name for a temporary file.
43 If the argument
44 .I s
45 is NULL this name is generated in an internal static buffer
46 and may be overwritten by the next call to
47 .BR tmpnam ().
48 If
49 .I s
50 is not NULL, the name is copied to the character array (of length
51 at least
52 .IR L_tmpnam )
53 pointed to by
54 .I s
55 and the value
56 .I s
57 is returned in case of success.
58 .LP
59 The pathname that is created, has a directory prefix
60 .IR P_tmpdir .
61 (Both
62 .I L_tmpnam
63 and
64 .I P_tmpdir
65 are defined in
66 .IR <stdio.h> ,
67 just like the
68 .B TMP_MAX
69 mentioned below.)
70 .SH RETURN VALUE
71 The
72 .BR tmpnam ()
73 function returns a pointer to a unique temporary
74 filename, or NULL if a unique name cannot be generated.
75 .SH ERRORS
76 No errors are defined.
77 .SH CONFORMING TO
78 SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
79 POSIX.1-2008 marks
80 .BR tmpnam ()
81 as obsolete.
82 .SH NOTES
83 The
84 .BR tmpnam ()
85 function generates a different string each time it is called,
86 up to
87 .B TMP_MAX
88 times.
89 If it is called more than
90 .B TMP_MAX
91 times,
92 the behavior is implementation defined.
93 .LP
94 Although
95 .BR tmpnam ()
96 generates names that are difficult to guess,
97 it is nevertheless possible that between the time that
98 .BR tmpnam ()
99 returns a pathname, and the time that the program opens it,
100 another program might create that pathname using
101 .BR open (2),
102 or create it as a symbolic link.
103 This can lead to security holes.
104 To avoid such possibilities, use the
105 .BR open (2)
106 .B O_EXCL
107 flag to open the pathname.
108 Or better yet, use
109 .BR mkstemp (3)
110 or
111 .BR tmpfile (3).
112 .LP
113 Portable applications that use threads cannot call
114 .BR tmpnam ()
115 with a NULL argument if either
116 .B _POSIX_THREADS
117 or
118 .B _POSIX_THREAD_SAFE_FUNCTIONS
119 is defined.
120 .LP
121 A POSIX draft proposed to use a function
122 .BR tmpnam_r ()
123 defined by
124 .sp
125 .nf
126 .in +4n
127 char *
128 tmpnam_r(char *s)
129 {
130     return s ? tmpnam(s) : NULL;
131 }
132 .in
133 .fi
134 .sp
135 apparently as a warning not to use NULL.
136 A few systems implement it.
137 To get a glibc prototype for this function from
138 .IR <stdio.h> ,
139 define
140 .B _SVID_SOURCE
141 or
142 .B _BSD_SOURCE
143 (before including
144 .I any
145 header file).
146 .SH BUGS
147 Never use this function.
148 Use
149 .BR mkstemp (3)
150 or
151 .BR tmpfile (3)
152 instead.
153 .SH SEE ALSO
154 .BR mkstemp (3),
155 .BR mktemp (3),
156 .BR tempnam (3),
157 .BR tmpfile (3)