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
11
13 tmpfile — create a temporary file
14
16 #include <stdio.h>
17
18 FILE *tmpfile(void);
19
21 The functionality described on this reference page is aligned with the
22 ISO C standard. Any conflict between the requirements described here
23 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
24 defers to the ISO C standard.
25
26 The tmpfile() function shall create a temporary file and open a corre‐
27 sponding stream. The file shall be automatically deleted when all ref‐
28 erences to the file are closed. The file is opened as in fopen() for
29 update (w+), except that implementations may restrict the permissions,
30 either by clearing the file mode bits or setting them to the value
31 S_IRUSR | S_IWUSR.
32
33 In some implementations, a permanent file may be left behind if the
34 process calling tmpfile() is killed while it is processing a call to
35 tmpfile().
36
37 An error message may be written to standard error if the stream cannot
38 be opened.
39
41 Upon successful completion, tmpfile() shall return a pointer to the
42 stream of the file that is created. Otherwise, it shall return a null
43 pointer and set errno to indicate the error.
44
46 The tmpfile() function shall fail if:
47
48 EINTR A signal was caught during tmpfile().
49
50 EMFILE All file descriptors available to the process are currently
51 open.
52
53 EMFILE {STREAM_MAX} streams are currently open in the calling process.
54
55 ENFILE The maximum allowable number of files is currently open in the
56 system.
57
58 ENOSPC The directory or file system which would contain the new file
59 cannot be expanded.
60
61 EOVERFLOW
62 The file is a regular file and the size of the file cannot be
63 represented correctly in an object of type off_t.
64
65 The tmpfile() function may fail if:
66
67 EMFILE {FOPEN_MAX} streams are currently open in the calling process.
68
69 ENOMEM Insufficient storage space is available.
70
71 The following sections are informative.
72
74 Creating a Temporary File
75 The following example creates a temporary file for update, and returns
76 a pointer to a stream for the created file in the fp variable.
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‐2008, <stdio.h>
102
104 Portions of this text are reprinted and reproduced in electronic form
105 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
106 -- Portable Operating System Interface (POSIX), The Open Group Base
107 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
108 cal and Electronics Engineers, Inc and The Open Group. (This is
109 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
110 event of any discrepancy between this version and the original IEEE and
111 The Open Group Standard, the original IEEE and The Open Group Standard
112 is the referee document. The original Standard can be obtained online
113 at http://www.unix.org/online.html .
114
115 Any typographical or formatting errors that appear in this page are
116 most likely to have been introduced during the conversion of the source
117 files to man page format. To report such errors, see https://www.ker‐
118 nel.org/doc/man-pages/reporting_bugs.html .
119
120
121
122IEEE/The Open Group 2013 TMPFILE(3P)