2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
44 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
46 .TH FDOPEN 3C "Apr 18, 2006"
48 fdopen \- associate a stream with a file descriptor
54 \fBFILE *\fR\fBfdopen\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fImode\fR);
60 The \fBfdopen()\fR function associates a stream with a file descriptor
64 The \fImode\fR argument is a character string having one of the following
72 \fBr\fR or \fBrb\fR Open a file for reading.
73 \fBw\fR or \fBwb\fR Open a file for writing.
74 \fBa\fR or \fBab\fR Open a file for writing at end of file.
75 \fBr+\fR, \fBrb+\fR or \fBr+b\fR T{
76 Open a file for update (reading and writing).
78 \fBw+\fR, \fBwb+\fR or \fBw+b\fR T{
79 Open a file for update (reading and writing).
81 \fBa+\fR, \fBab+\fR or \fBa+b\fR T{
82 Open a file for update (reading and writing) at end of file.
88 The meaning of these flags is exactly as specified for the \fBfopen\fR(3C)
89 function, except that modes beginning with \fIw\fR do not cause truncation of
90 the file. A trailing \fBF\fR character can also be included in the \fImode\fR
91 argument as described in \fBfopen\fR(3C) to enable extended FILE facility.
94 The mode of the stream must be allowed by the file access mode of the open
95 file. The file position indicator associated with the new stream is set to the
96 position indicated by the file offset associated with the file descriptor.
99 The \fBfdopen()\fR function preserves the offset maximum previously set for the
100 open file description corresponding to \fIfildes\fR.
103 The error and end-of-file indicators for the stream are cleared. The
104 \fBfdopen()\fR function may cause the \fBst_atime\fR field of the underlying
105 file to be marked for update.
108 If \fIfildes\fR refers to a shared memory object, the result of the
109 \fBfdopen()\fR function is unspecified.
113 Upon successful completion, \fBfdopen()\fR returns a pointer to a stream.
114 Otherwise, a null pointer is returned and \fBerrno\fR is set to indicate the
118 The \fBfdopen()\fR function may fail and not set \fBerrno\fR if there are no
119 free \fBstdio\fR streams.
123 The \fBfdopen()\fR function may fail if:
130 The \fIfildes\fR argument is not a valid file descriptor.
139 The \fImode\fR argument is not a valid mode.
148 {\fBFOPEN_MAX\fR} streams are currently open in the calling process.
150 {\fBSTREAM_MAX\fR} streams are currently open in the calling process.
159 There is insufficient space to allocate a buffer.
165 A process is allowed to have at least {\fBFOPEN_MAX\fR} \fBstdio\fR streams
166 open at a time. For 32-bit applications, however, the underlying ABIs formerly
167 required that no file descriptor used to access the file underlying a
168 \fBstdio\fR stream have a value greater than 255. To maintain binary
169 compatibility with earlier Solaris releases, this limit still constrains 32-bit
173 File descriptors are obtained from calls like \fBopen\fR(2), \fBdup\fR(2),
174 \fBcreat\fR(2) or \fBpipe\fR(2), which open files but do not return streams.
175 Streams are necessary input for almost all of the standard I/O library
180 See \fBattributes\fR(5) for descriptions of the following attributes:
188 ATTRIBUTE TYPE ATTRIBUTE VALUE
190 Interface Stability See below.
197 The \fBF\fR character in the \fImode\fR argument is Evolving. In all other
198 respects this function is Standard.
202 \fBcreat\fR(2), \fBdup\fR(2), \fBopen\fR(2), \fBpipe\fR(2), \fBfclose\fR(3C),
203 \fBfopen\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)