xref: /386bsd/usr/share/man/cat3/tmpnam.0 (revision a2142627)
1TMPFILE(3)                386BSD Programmer's Manual                TMPFILE(3)
2
3NNAAMMEE
4     tteemmppnnaamm, ttmmppffiillee, ttmmppnnaamm - temporary file routines
5
6SSYYNNOOPPSSIISS
7     ##iinncclluuddee <<ssttddiioo..hh>>
8
9     _F_I_L_E *
10     ttmmppffiillee(_v_o_i_d)
11
12     _c_h_a_r *
13     ttmmppnnaamm(_c_h_a_r *_s_t_r)
14
15     _c_h_a_r *
16     tteemmppnnaamm(_c_o_n_s_t _c_h_a_r *_t_m_p_d_i_r, _c_o_n_s_t _c_h_a_r *_p_r_e_f_i_x)
17
18DDEESSCCRRIIPPTTIIOONN
19     The ttmmppffiillee() function returns a pointer to a stream associated with a
20     file descriptor returned by the routine mkstemp(3).  The created file is
21     unlinked before ttmmppffiillee() returns, causing the file to be automatically
22     deleted when the last reference to it is closed.  The file is opened with
23     the access value `w+'.
24
25     The ttmmppnnaamm() function returns a pointer to a file name, in the P_tmpdir
26     directory, which did not reference an existing file at some indeterminate
27     point in the past.  P_tmpdir is defined in the include file <_s_t_d_i_o._h>. If
28     the argument _s is non-NULL, the file name is copied to the buffer it
29     references.  Otherwise, the file name is copied to a static buffer.  In
30     either case, ttmmppnnaamm() returns a pointer to the file name.
31
32     The buffer referenced by _s is expected to be at least L_tmpnam bytes in
33     length.  L_tmpnam is defined in the include file <_s_t_d_i_o._h>.
34
35     The tteemmppnnaamm() function is similar to ttmmppnnaamm(), but provides the ability
36     to specify the directory which will contain the temporary file and the
37     file name prefix.
38
39     The environment variable TMPDIR (if set), the argument _d_i_r (if non-NULL),
40     the directory P_tmpdir, and the directory /_t_m_p are tried, in the listed
41     order, as directories in which to store the temporary file.
42
43     The argument _p_r_e_f_i_x, if non-NULL, is used to specify a file name prefix,
44     which will be the first part of the created file name.  TTeemmppnnaamm()
45     allocates memory in which to store the file name; the returned pointer
46     may be used as a subsequent argument to free(3).
47
48RREETTUURRNN VVAALLUUEESS
49     The ttmmppffiillee() function returns a pointer to an open file stream on
50     success, and a NULL pointer on error.
51
52     The ttmmppnnaamm() and tteemmppffiillee() functions return a pointer to a file name on
53     success, and a NULL pointer on error.
54
55EERRRROORRSS
56     The ttmmppffiillee() function may fail and set the global variable _e_r_r_n_o for any
57     of the errors specified for the library functions fdopen(3) or
58     mkstemp(3).
59
60     The ttmmppnnaamm() function may fail and set _e_r_r_n_o for any of the errors
61     specified for the library function mktemp(3).
62
63     The tteemmppnnaamm() function may fail and set _e_r_r_n_o for any of the errors
64     specified for the library functions malloc(3) or mktemp(3).
65
66SSEEEE AALLSSOO
67     mkstemp(3),  mktemp(3)
68
69SSTTAANNDDAARRDDSS
70     The ttmmppffiillee() and ttmmppnnaamm() functions conform to ANSI C3.159-1989 (``ANSI
71     C'').
72
73BBUUGGSS
74     These interfaces are provided for System V and ANSI compatibility only.
75     The mkstemp(3) interface is strongly preferred.
76
77     There are four important problems with these interfaces (as well as with
78     the historic mktemp(3) interface).  First, there is an obvious race
79     between file name selection and file creation and deletion.  Second, most
80     historic implementations provide only a limited number of possible
81     temporary file names (usually 26) before file names will start being
82     recycled.  Third, the System V implementations of these functions (and of
83     mktemp)  use the access(2) function to determine whether or not the
84     temporary file may be created.  This has obvious ramifications for setuid
85     or setgid programs, complicating the portable use of these interfaces in
86     such programs.  Finally, there is no specification of the permissions
87     with which the temporary files are created.
88
89     This implementation does not have these flaws, but portable software
90     cannot depend on that.  In particular, the ttmmppffiillee() interface should not
91     be used in software expected to be used on other systems if there is any
92     possibility that the user does not wish the temporary file to be publicly
93     readable and writable.
94
95BSD Experimental                 June 29, 1991                               2
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133