1TMPFILE(3P) POSIX Programmer's Manual TMPFILE(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 tmpfile — create a temporary file
13
15 #include <stdio.h>
16
17 FILE *tmpfile(void);
18
20 The functionality described on this reference page is aligned with the
21 ISO C standard. Any conflict between the requirements described here
22 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
23 defers to the ISO C standard.
24
25 The tmpfile() function shall create a temporary file and open a corre‐
26 sponding stream. The file shall be automatically deleted when all ref‐
27 erences to the file are closed. The file shall be opened as in fopen()
28 for update (wb+), except that implementations may restrict the permis‐
29 sions, either by clearing the file mode bits or setting them to the
30 value S_IRUSR | S_IWUSR.
31
32 In some implementations, a permanent file may be left behind if the
33 process calling tmpfile() is killed while it is processing a call to
34 tmpfile().
35
36 An error message may be written to standard error if the stream cannot
37 be opened.
38
40 Upon successful completion, tmpfile() shall return a pointer to the
41 stream of the file that is created. Otherwise, it shall return a null
42 pointer and set errno to indicate the error.
43
45 The tmpfile() function shall fail if:
46
47 EINTR A signal was caught during tmpfile().
48
49 EMFILE All file descriptors available to the process are currently
50 open.
51
52 EMFILE {STREAM_MAX} streams are currently open in the calling process.
53
54 ENFILE The maximum allowable number of files is currently open in the
55 system.
56
57 ENOSPC The directory or file system which would contain the new file
58 cannot be expanded.
59
60 EOVERFLOW
61 The file is a regular file and the size of the file cannot be
62 represented correctly in an object of type off_t.
63
64 The tmpfile() function may fail if:
65
66 EMFILE {FOPEN_MAX} streams are currently open in the calling process.
67
68 ENOMEM Insufficient storage space is available.
69
70 The following sections are informative.
71
73 Creating a Temporary File
74 The following example creates a temporary file for update, and returns
75 a pointer to a stream for the created file in the fp variable.
76
77
78 #include <stdio.h>
79 ...
80 FILE *fp;
81
82 fp = tmpfile ();
83
85 It should be possible to open at least {TMP_MAX} temporary files during
86 the lifetime of the program (this limit may be shared with tmpnam())
87 and there should be no limit on the number simultaneously open other
88 than this limit and any limit on the number of open file descriptors or
89 streams ({OPEN_MAX}, {FOPEN_MAX}, {STREAM_MAX}).
90
92 None.
93
95 None.
96
98 Section 2.5, Standard I/O Streams, fopen(), mkdtemp(), tmpnam(),
99 unlink()
100
101 The Base Definitions volume of POSIX.1‐2017, <stdio.h>
102
104 Portions of this text are reprinted and reproduced in electronic form
105 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
106 table Operating System Interface (POSIX), The Open Group Base Specifi‐
107 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
108 Electrical and Electronics Engineers, Inc and The Open Group. In the
109 event of any discrepancy between this version and the original IEEE and
110 The Open Group Standard, the original IEEE and The Open Group Standard
111 is the referee document. The original Standard can be obtained online
112 at http://www.opengroup.org/unix/online.html .
113
114 Any typographical or formatting errors that appear in this page are
115 most likely to have been introduced during the conversion of the source
116 files to man page format. To report such errors, see https://www.ker‐
117 nel.org/doc/man-pages/reporting_bugs.html .
118
119
120
121IEEE/The Open Group 2017 TMPFILE(3P)