TMPFILE(3) 1990 TMPFILE(3)
tempnam, tmpfile, tmpnam - temporary file routines
S
\bSY
\bYN
\bNO
\bOP
\bPS
\bSI
\bIS
\bS
#
\b#i
\bin
\bnc
\bcl
\blu
\bud
\bde
\be <
\b<s
\bst
\btd
\bdi
\bio
\bo.
\b.h
\bh>
\b>
t
\btm
\bmp
\bpf
\bfi
\bil
\ble
\be(
\b(v
\bvo
\boi
\bid
\bd)
\b);
\b;
t
\btm
\bmp
\bpn
\bna
\bam
\bm(
\b(c
\bch
\bha
\bar
\br *
\b*s
\bst
\btr
\br)
\b);
\b;
t
\bte
\bem
\bmp
\bpn
\bna
\bam
\bm(
\b(c
\bco
\bon
\bns
\bst
\bt c
\bch
\bha
\bar
\br *
\b*t
\btm
\bmp
\bpd
\bdi
\bir
\br,
\b, c
\bco
\bon
\bns
\bst
\bt c
\bch
\bha
\bar
\br *
\b*p
\bpr
\bre
\bef
\bfi
\bix
\bx)
\b);
\b;
D
\bDE
\bES
\bSC
\bCR
\bRI
\bIP
\bPT
\bTI
\bIO
\bON
\bN
_
\bT_
\bm_
\bp_
\bf_
\bi_
\bl_
\be opens a file using a file name generated by the rou-
tine _
\bt_
\bm_
\bp_
\bn_
\ba_
\bm(3), and returns a pointer to the stream associ-
ated with the file. The created file is unlinked before
_
\bt_
\bm_
\bp_
\bf_
\bi_
\bl_
\be returns, causing the contents of the file to be
deleted automatically when the last reference to it is
closed. The file is opened with the access value ``w+''.
If _
\bt_
\bm_
\bp_
\bn_
\ba_
\bm returns NULL, or if _
\bt_
\bm_
\bp_
\bf_
\bi_
\bl_
\be is unable to open the
file, a NULL pointer is returned.
_
\bT_
\bm_
\bp_
\bn_
\ba_
\bm returns a pointer to a file name, in the directory
``/usr/tmp'', which did not reference an existing file at
some indeterminate point in the past. If the argument _
\bs is
non-NULL, this file name is copied to the buffer it refer-
ences. Otherwise, memory to contain this file name is allo-
cated by _
\bt_
\bm_
\bp_
\bn_
\ba_
\bm. In either case, _
\bt_
\bm_
\bp_
\bn_
\ba_
\bm returns a pointer
to the file name; in the latter case, the return value may
be used as a subsequent argument to _
\bf_
\br_
\be_
\be(3).
In the current implementation, the memory buffer referenced
by _
\bs must be at least 16 bytes long.
_
\bT_
\be_
\bm_
\bp_
\bn_
\ba_
\bm is similar to _
\bt_
\bm_
\bp_
\bn_
\ba_
\bm, but provides the ability to
specify the directory which will contain the temporary file
and the file name prefix.
The environmental variable ``TMPDIR'' (if set), the argument
_
\bd_
\bi_
\br (if non-NULL), the directory ``/usr/tmp'' and the direc-
tory ``/tmp'' are tried, in the listed order, as directories
in which to store the temporary file. _
\bT_
\be_
\bm_
\bp_
\bn_
\ba_
\bm allocates
memory in which to store the file name; the returned pointer
may be used as a subsequent argument to _
\bf_
\br_
\be_
\be(3). The argu-
ment _
\bp_
\br_
\be_
\bf_
\bi_
\bx, if non-NULL, is used to specify a file name
prefix, which will be the first part of the created file
TMPFILE(3) 1990 TMPFILE(3)
_
\bT_
\bm_
\bp_
\bn_
\ba_
\bm and _
\bt_
\be_
\bm_
\bp_
\bn_
\ba_
\bm_
\be return a NULL pointer if unable to allo-
cate memory or find a file which may be created.
The manifest constants ``TMP_MAX'', ``P_tmpdir'' and
``L_tmpnam'', documented for the routines _
\bt_
\bm_
\bp_
\bn_
\ba_
\bm and _
\bt_
\be_
\bm_
\bp_
\bn_
\ba_
\bm
in other systems, are not available in this implementation.
If the source code requires them, simply use:
#define TMP_MAX 308915776
#define P_tmpdir "/usr/tmp"
These interfaces are provided for System V compatibility
only. The _
\bm_
\bk_
\bs_
\bt_
\be_
\bm_
\bp(3) interface is strongly preferred.
There are three important problems with these interfaces (as
well as with the historic _
\bm_
\bk_
\bt_
\be_
\bm_
\bp(3) interface). First,
there is an obvious race between file name selection and
file creation. Second, most implementations provide only a
limited number (usually 26) of possible temporary file names
before file names will start being recycled. Third, the
System V implementations of these functions (and _
\bm_
\bk_
\bt_
\be_
\bm_
\bp) use
the _
\ba_
\bc_
\bc_
\be_
\bs_
\bs(2) system call to determine whether or not the
temporary file may be created. This has obvious ramifica-
tions for setuid or setgid programs, complicating the port-
able use of these interfaces in such programs.
The _
\bm_
\bk_
\bs_
\bt_
\be_
\bm_
\bp(3) interface has none of these problems; the
_
\bm_
\bk_
\bt_
\be_
\bm_
\bp(_
\b3) implementation in this system suffers only from
the race condition described above.
The _
\bt_
\bm_
\bp_
\bf_
\bi_
\bl_
\be interface should not be used if there is any
possibility that the user does not wish the temporary file
to be publicly readable or writable.
S
\bSE
\bEE
\bE A
\bAL
\bLS
\bSO
\bO
fopen(3), mkstemp(3), mktemp(3)