Merge commit 'b31320a79e2054c6739b5229259dbf98f3afc547' into merges
[unleashed.git] / share / man / man3c / fdopen.3c
blobee9f3c95ee8b5eb8838abba8dbe3c76d344f1493
1 '\" te
2 .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions 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.
7 .\"  This notice shall appear on any product containing this material.
8 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
9 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
10 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
11 .TH FDOPEN 3C "Apr 18, 2006"
12 .SH NAME
13 fdopen \- associate a stream with a file descriptor
14 .SH SYNOPSIS
15 .LP
16 .nf
17 #include <stdio.h>
19 \fBFILE *\fR\fBfdopen\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fImode\fR);
20 .fi
22 .SH DESCRIPTION
23 .sp
24 .LP
25 The \fBfdopen()\fR function associates a stream with a file descriptor
26 \fIfildes\fR.
27 .sp
28 .LP
29 The \fImode\fR argument is a character string having one of the following
30 values:
31 .sp
33 .sp
34 .TS
35 l l
36 l l .
37 \fBr\fR or \fBrb\fR     Open a file for reading.
38 \fBw\fR or \fBwb\fR     Open a file for writing.
39 \fBa\fR or \fBab\fR     Open a file for writing at end of file.
40 \fBr+\fR, \fBrb+\fR or \fBr+b\fR        T{
41 Open a file for update (reading and writing).
43 \fBw+\fR, \fBwb+\fR or \fBw+b\fR        T{
44 Open a file for update (reading and writing).
46 \fBa+\fR, \fBab+\fR or \fBa+b\fR        T{
47 Open a file for update (reading and writing) at end of file.
49 .TE
51 .sp
52 .LP
53 The meaning of these flags is exactly as specified for the \fBfopen\fR(3C)
54 function, except that modes beginning with \fIw\fR do not cause truncation of
55 the file. A trailing \fBF\fR character can also be included in the \fImode\fR
56 argument as described in \fBfopen\fR(3C) to enable extended FILE facility.
57 .sp
58 .LP
59 The mode of the stream must be allowed by the file access mode of the open
60 file. The file position indicator associated with the new stream is set to the
61 position indicated by the file offset associated with the file descriptor.
62 .sp
63 .LP
64 The \fBfdopen()\fR function preserves the offset maximum previously set for the
65 open file description corresponding to  \fIfildes\fR.
66 .sp
67 .LP
68 The error and end-of-file indicators for the stream are cleared. The
69 \fBfdopen()\fR function may cause the \fBst_atime\fR field of the underlying
70 file to be marked for update.
71 .sp
72 .LP
73 If \fIfildes\fR refers to a shared memory object, the result of the
74 \fBfdopen()\fR function is unspecified.
75 .SH RETURN VALUES
76 .sp
77 .LP
78 Upon successful completion, \fBfdopen()\fR returns a pointer to a stream.
79 Otherwise, a null pointer is returned and \fBerrno\fR is set to indicate the
80 error.
81 .sp
82 .LP
83 The \fBfdopen()\fR function may fail and not set \fBerrno\fR if there are no
84 free \fBstdio\fR streams.
85 .SH ERRORS
86 .sp
87 .LP
88 The \fBfdopen()\fR function may fail if:
89 .sp
90 .ne 2
91 .na
92 \fB\fBEBADF\fR\fR
93 .ad
94 .RS 10n
95 The \fIfildes\fR argument is not a valid file descriptor.
96 .RE
98 .sp
99 .ne 2
101 \fB\fBEINVAL\fR\fR
103 .RS 10n
104 The \fImode\fR argument is not a valid mode.
108 .ne 2
110 \fB\fBEMFILE\fR\fR
112 .RS 10n
113 {\fBFOPEN_MAX\fR} streams are currently open in the calling process.
115 {\fBSTREAM_MAX\fR} streams are currently open in the calling process.
119 .ne 2
121 \fB\fBENOMEM\fR\fR
123 .RS 10n
124 There is insufficient space to allocate a buffer.
127 .SH USAGE
130 A process is allowed to have at least {\fBFOPEN_MAX\fR} \fBstdio\fR streams
131 open at a time. For 32-bit applications, however, the underlying ABIs formerly
132 required that no file descriptor used to access the file underlying a
133 \fBstdio\fR stream have a value greater than 255. To maintain binary
134 compatibility with earlier Solaris releases, this limit still constrains 32-bit
135 applications.
138 File descriptors are obtained from calls like \fBopen\fR(2), \fBdup\fR(2),
139 \fBcreat\fR(2) or \fBpipe\fR(2), which open files but do not return streams.
140 Streams are necessary input for almost all of the standard I/O library
141 functions.
142 .SH ATTRIBUTES
145 See \fBattributes\fR(5) for descriptions of the following attributes:
150 box;
151 c | c
152 l | l .
153 ATTRIBUTE TYPE  ATTRIBUTE VALUE
155 Interface Stability     See below.
157 MT-Level        MT-Safe
162 The \fBF\fR character in the \fImode\fR argument is Evolving. In all other
163 respects this function is Standard.
164 .SH SEE ALSO
167 \fBcreat\fR(2), \fBdup\fR(2), \fBopen\fR(2), \fBpipe\fR(2), \fBfclose\fR(3C),
168 \fBfopen\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)