summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2017/man3p/fdopen.3p
blob: 0b8a1555673309b3008d01f34c714bd7e6a68202 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'\" et
.TH FDOPEN "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.\"
.SH NAME
fdopen
\(em associate a stream with a file descriptor
.SH SYNOPSIS
.LP
.nf
#include <stdio.h>
.P
FILE *fdopen(int \fIfildes\fP, const char *\fImode\fP);
.fi
.SH DESCRIPTION
The
\fIfdopen\fR()
function shall associate a stream with a file descriptor.
.P
The
.IR mode
argument is a character string having one of the following values:
.IP "\fIr\fP\ or\ \fIrb\fP" 14
Open a file for reading.
.IP "\fIw\fP\ or\ \fIwb\fP" 14
Open a file for writing.
.IP "\fIa\fP\ or\ \fIab\fP" 14
Open a file for writing at end-of-file.
.IP "\fIr\fP+\ or\ \fIrb\fP+\ or\ \fIr\fP+\fIb\fP" 14
Open a file for update (reading and writing).
.IP "\fIw\fP+\ or\ \fIwb\fP+\ or\ \fIw\fP+\fIb\fP" 14
Open a file for update (reading and writing).
.IP "\fIa\fP+\ or\ \fIab\fP+\ or\ \fIa\fP+\fIb\fP" 14
Open a file for update (reading and writing) at end-of-file.
.P
The meaning of these flags is exactly as specified in
\fIfopen\fR(),
except that modes beginning with
.IR w
shall not cause truncation of the file.
.P
Additional values for the
.IR mode
argument may be supported by an implementation.
.P
The application shall ensure that the mode of the stream as expressed
by the
.IR mode
argument is allowed by the file access mode of the open file
description to which
.IR fildes
refers. The file position indicator associated with the new stream is
set to the position indicated by the file offset associated with the
file descriptor.
.P
The error and end-of-file indicators for the stream shall be cleared.
The
\fIfdopen\fR()
function may cause the last data access timestamp of the underlying
file to be marked for update.
.P
If
.IR fildes
refers to a shared memory object, the result of the
\fIfdopen\fR()
function is unspecified.
.P
If
.IR fildes
refers to a typed memory object, the result of the
\fIfdopen\fR()
function is unspecified.
.P
The
\fIfdopen\fR()
function shall preserve the offset maximum previously set for the
open file description corresponding to
.IR fildes .
.SH "RETURN VALUE"
Upon successful completion,
\fIfdopen\fR()
shall return a pointer to a stream; otherwise, a null pointer shall be
returned and
.IR errno
set to indicate the error.
.SH ERRORS
The
\fIfdopen\fR()
function shall fail if:
.TP
.BR EMFILE
{STREAM_MAX}
streams are currently open in the calling process.
.P
The
\fIfdopen\fR()
function may fail if:
.TP
.BR EBADF
The
.IR fildes
argument is not a valid file descriptor.
.TP
.BR EINVAL
The
.IR mode
argument is not a valid mode.
.TP
.BR EMFILE
{FOPEN_MAX}
streams are currently open in the calling process.
.TP
.BR ENOMEM
Insufficient space to allocate a buffer.
.LP
.IR "The following sections are informative."
.SH EXAMPLES
None.
.SH "APPLICATION USAGE"
File descriptors are obtained from calls like
\fIopen\fR(),
\fIdup\fR(),
\fIcreat\fR(),
or
\fIpipe\fR(),
which open files but do not return streams.
.SH RATIONALE
The file descriptor may have been obtained from
\fIopen\fR(),
\fIcreat\fR(),
\fIpipe\fR(),
\fIdup\fR(),
\fIfcntl\fR(),
or
\fIsocket\fR();
inherited through
\fIfork\fR(),
\fIposix_spawn\fR(),
or
.IR exec ;
or perhaps obtained by other means.
.P
The meanings of the
.IR mode
arguments of
\fIfdopen\fR()
and
\fIfopen\fR()
differ. With
\fIfdopen\fR(),
open for write (\fIw\fP or \fIw+\fP) does not truncate, and append
(\fIa\fP or \fIa+\fP) cannot create for writing. The
.IR mode
argument formats that include a \fIb\fP are allowed for consistency
with the ISO\ C standard function
\fIfopen\fR().
The \fIb\fP has no effect on the resulting stream. Although not
explicitly required by this volume of POSIX.1\(hy2017, a good implementation of append (\fIa\fP)
mode would cause the O_APPEND flag to be set.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Section 2.5.1" ", " "Interaction of File Descriptors and Standard I/O Streams",
.IR "\fIfclose\fR\^(\|)",
.IR "\fIfmemopen\fR\^(\|)",
.IR "\fIfopen\fR\^(\|)",
.IR "\fIopen\fR\^(\|)",
.IR "\fIopen_memstream\fR\^(\|)",
.IR "\fIposix_spawn\fR\^(\|)",
.IR "\fIsocket\fR\^(\|)"
.P
The Base Definitions volume of POSIX.1\(hy2017,
.IR "\fB<stdio.h>\fP"
.\"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1-2017, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, 2018 Edition,
Copyright (C) 2018 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
In the event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
.PP
Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .