3 <<tmpfile>>---create a temporary file
14 FILE *_tmpfile_r(struct _reent *<[reent]>);
17 Create a temporary file (a file which will be deleted automatically),
18 using a name generated by <<tmpnam>>. The temporary file is opened with
19 the mode <<"wb+">>, permitting you to read and write anywhere in it
20 as a binary file (without any data transformations the host system may
21 perform for text files).
23 The alternate function <<_tmpfile_r>> is a reentrant version. The
24 argument <[reent]> is a pointer to a reentrancy structure.
27 <<tmpfile>> normally returns a pointer to the temporary file. If no
28 temporary file could be created, the result is NULL, and <<errno>>
29 records the reason for failure.
32 Both ANSI C and the System V Interface Definition (Issue 2) require
35 Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>,
36 <<isatty>>, <<lseek>>, <<open>>, <<read>>, <<sbrk>>, <<write>>.
38 <<tmpfile>> also requires the global pointer <<environ>>.
53 _tmpfile_r (struct _reent
*ptr
)
63 if ((f
= _tmpnam_r (ptr
, buf
)) == NULL
)
65 fd
= _open_r (ptr
, f
, O_RDWR
| O_CREAT
| O_EXCL
| O_BINARY
,
68 while (fd
< 0 && _REENT_ERRNO(ptr
) == EEXIST
);
71 fp
= _fdopen_r (ptr
, fd
, "wb+");
72 e
= _REENT_ERRNO(ptr
);
75 (void) _remove_r (ptr
, f
);
76 _REENT_ERRNO(ptr
) = e
;
85 return _tmpfile_r (_REENT
);