1FDOPEN(3P) POSIX Programmer's Manual FDOPEN(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 fdopen — associate a stream with a file descriptor
14
16 #include <stdio.h>
17
18 FILE *fdopen(int fildes, const char *mode);
19
21 The fdopen() function shall associate a stream with a file descriptor.
22
23 The mode argument is a character string having one of the following
24 values:
25
26 r or rb Open a file for reading.
27
28 w or wb Open a file for writing.
29
30 a or ab Open a file for writing at end-of-file.
31
32 r+ or rb+ or r+b
33 Open a file for update (reading and writing).
34
35 w+ or wb+ or w+b
36 Open a file for update (reading and writing).
37
38 a+ or ab+ or a+b
39 Open a file for update (reading and writing) at end-of-
40 file.
41
42 The meaning of these flags is exactly as specified in fopen(), except
43 that modes beginning with w shall not cause truncation of the file.
44
45 Additional values for the mode argument may be supported by an imple‐
46 mentation.
47
48 The application shall ensure that the mode of the stream as expressed
49 by the mode argument is allowed by the file access mode of the open
50 file description to which fildes refers. The file position indicator
51 associated with the new stream is set to the position indicated by the
52 file offset associated with the file descriptor.
53
54 The error and end-of-file indicators for the stream shall be cleared.
55 The fdopen() function may cause the last data access timestamp of the
56 underlying file to be marked for update.
57
58 If fildes refers to a shared memory object, the result of the fdopen()
59 function is unspecified.
60
61 If fildes refers to a typed memory object, the result of the fdopen()
62 function is unspecified.
63
64 The fdopen() function shall preserve the offset maximum previously set
65 for the open file description corresponding to fildes.
66
68 Upon successful completion, fdopen() shall return a pointer to a
69 stream; otherwise, a null pointer shall be returned and errno set to
70 indicate the error.
71
73 The fdopen() function shall fail if:
74
75 EMFILE {STREAM_MAX} streams are currently open in the calling process.
76
77 The fdopen() function may fail if:
78
79 EBADF The fildes argument is not a valid file descriptor.
80
81 EINVAL The mode argument is not a valid mode.
82
83 EMFILE {FOPEN_MAX} streams are currently open in the calling process.
84
85 ENOMEM Insufficient space to allocate a buffer.
86
87 The following sections are informative.
88
90 None.
91
93 File descriptors are obtained from calls like open(), dup(), creat(),
94 or pipe(), which open files but do not return streams.
95
97 The file descriptor may have been obtained from open(), creat(),
98 pipe(), dup(), fcntl(), or socket(); inherited through fork(),
99 posix_spawn(), or exec; or perhaps obtained by other means.
100
101 The meanings of the mode arguments of fdopen() and fopen() differ. With
102 fdopen(), open for write (w or w+) does not truncate, and append (a or
103 a+) cannot create for writing. The mode argument formats that include a
104 b are allowed for consistency with the ISO C standard function fopen().
105 The b has no effect on the resulting stream. Although not explicitly
106 required by this volume of POSIX.1‐2008, a good implementation of
107 append (a) mode would cause the O_APPEND flag to be set.
108
110 None.
111
113 Section 2.5.1, Interaction of File Descriptors and Standard I/O
114 Streams, fclose(), fmemopen(), fopen(), open(), open_memstream(),
115 posix_spawn(), socket()
116
117 The Base Definitions volume of POSIX.1‐2008, <stdio.h>
118
120 Portions of this text are reprinted and reproduced in electronic form
121 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
122 -- Portable Operating System Interface (POSIX), The Open Group Base
123 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
124 cal and Electronics Engineers, Inc and The Open Group. (This is
125 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
126 event of any discrepancy between this version and the original IEEE and
127 The Open Group Standard, the original IEEE and The Open Group Standard
128 is the referee document. The original Standard can be obtained online
129 at http://www.unix.org/online.html .
130
131 Any typographical or formatting errors that appear in this page are
132 most likely to have been introduced during the conversion of the source
133 files to man page format. To report such errors, see https://www.ker‐
134 nel.org/doc/man-pages/reporting_bugs.html .
135
136
137
138IEEE/The Open Group 2013 FDOPEN(3P)