| 1 |
'\" t |
| 2 |
.\" Copyright 1993, David Metcalfe <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH tmpfile 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
tmpfile \- create a temporary file |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <stdio.h> |
| 16 |
.P |
| 17 |
.B FILE *tmpfile(void); |
| 18 |
.fi |
| 19 |
.SH DESCRIPTION |
| 20 |
The |
| 21 |
.BR tmpfile () |
| 22 |
function opens a unique temporary file |
| 23 |
in binary read/write (w+b) mode. |
| 24 |
The file will be automatically deleted when it is closed or the |
| 25 |
program terminates. |
| 26 |
.SH RETURN VALUE |
| 27 |
The |
| 28 |
.BR tmpfile () |
| 29 |
function returns a stream descriptor, or NULL if |
| 30 |
a unique filename cannot be generated or the unique file cannot be |
| 31 |
opened. |
| 32 |
In the latter case, |
| 33 |
.I errno |
| 34 |
is set to indicate the error. |
| 35 |
.SH ERRORS |
| 36 |
.TP |
| 37 |
.B EACCES |
| 38 |
Search permission denied for directory in file's path prefix. |
| 39 |
.TP |
| 40 |
.B EEXIST |
| 41 |
Unable to generate a unique filename. |
| 42 |
.TP |
| 43 |
.B EINTR |
| 44 |
The call was interrupted by a signal; |
| 45 |
see |
| 46 |
.BR signal (7). |
| 47 |
.TP |
| 48 |
.B EMFILE |
| 49 |
The per-process limit on the number of open file descriptors has been reached. |
| 50 |
.TP |
| 51 |
.B ENFILE |
| 52 |
The system-wide limit on the total number of open files has been reached. |
| 53 |
.TP |
| 54 |
.B ENOSPC |
| 55 |
There was no room in the directory to add the new filename. |
| 56 |
.TP |
| 57 |
.B EROFS |
| 58 |
Read-only filesystem. |
| 59 |
.SH ATTRIBUTES |
| 60 |
For an explanation of the terms used in this section, see |
| 61 |
.BR attributes (7). |
| 62 |
.TS |
| 63 |
allbox; |
| 64 |
lbx lb lb |
| 65 |
l l l. |
| 66 |
Interface Attribute Value |
| 67 |
T{ |
| 68 |
.na |
| 69 |
.nh |
| 70 |
.BR tmpfile () |
| 71 |
T} Thread safety MT-Safe |
| 72 |
.TE |
| 73 |
.SH VERSIONS |
| 74 |
The standard does not specify the directory that |
| 75 |
.BR tmpfile () |
| 76 |
will use. |
| 77 |
glibc will try the path prefix |
| 78 |
.I P_tmpdir |
| 79 |
defined |
| 80 |
in |
| 81 |
.IR <stdio.h> , |
| 82 |
and if that fails, then the directory |
| 83 |
.IR /tmp . |
| 84 |
.SH STANDARDS |
| 85 |
C11, POSIX.1-2008. |
| 86 |
.SH HISTORY |
| 87 |
POSIX.1-2001, C89, SVr4, 4.3BSD, SUSv2. |
| 88 |
.SH NOTES |
| 89 |
POSIX.1-2001 specifies: |
| 90 |
an error message may be written to |
| 91 |
.I stdout |
| 92 |
if the stream |
| 93 |
cannot be opened. |
| 94 |
.SH SEE ALSO |
| 95 |
.BR exit (3), |
| 96 |
.BR mkstemp (3), |
| 97 |
.BR mktemp (3), |
| 98 |
.BR tempnam (3), |
| 99 |
.BR tmpnam (3) |