mirror of https://github.com/mkerrisk/man-pages
139 lines
4.6 KiB
Plaintext
139 lines
4.6 KiB
Plaintext
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
|
|
.TH "FDOPEN" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
.\" fdopen
|
|
.SH NAME
|
|
fdopen \- associate a stream with a file descriptor
|
|
.SH SYNOPSIS
|
|
.LP
|
|
\fB#include <stdio.h>
|
|
.br
|
|
.sp
|
|
FILE *fdopen(int\fP \fIfildes\fP\fB, const char *\fP\fImode\fP\fB);
|
|
\fP
|
|
\fB
|
|
.br
|
|
\fP
|
|
.SH DESCRIPTION
|
|
.LP
|
|
The \fIfdopen\fP() function shall associate a stream with a file descriptor.
|
|
.LP
|
|
The \fImode\fP argument is a character string having one of the following
|
|
values:
|
|
.TP 7
|
|
\fIr\fP\ or\ \fIrb\fP
|
|
Open a file for reading.
|
|
.TP 7
|
|
\fIw\fP\ or\ \fIwb\fP
|
|
Open a file for writing.
|
|
.TP 7
|
|
\fIa\fP\ or\ \fIab\fP
|
|
Open a file for writing at end-of-file.
|
|
.TP 7
|
|
\fIr\fP+\ or\ \fIrb\fP+\ or\ \fIr\fP+\fIb\fP
|
|
Open a file for update (reading and writing).
|
|
.TP 7
|
|
\fIw\fP+\ or\ \fIwb\fP+\ or\ \fIw\fP+\fIb\fP
|
|
Open a file for update (reading and writing).
|
|
.TP 7
|
|
\fIa\fP+\ or\ \fIab\fP+\ or\ \fIa\fP+\fIb\fP
|
|
Open a file for update (reading and writing) at end-of-file.
|
|
.sp
|
|
.LP
|
|
The meaning of these flags is exactly as specified in \fIfopen\fP(),
|
|
except that modes
|
|
beginning with \fIw\fP shall not cause truncation of the file.
|
|
.LP
|
|
Additional values for the \fImode\fP argument may be supported by
|
|
an implementation.
|
|
.LP
|
|
The application shall ensure that the mode of the stream as expressed
|
|
by the \fImode\fP argument is allowed by the file access
|
|
mode of the open file description to which \fIfildes\fP 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.
|
|
.LP
|
|
The error and end-of-file indicators for the stream shall be cleared.
|
|
The \fIfdopen\fP() function may cause the \fIst_atime\fP
|
|
field of the underlying file to be marked for update.
|
|
.LP
|
|
If \fIfildes\fP refers to a shared memory object, the result of the
|
|
\fIfdopen\fP() function is unspecified.
|
|
.LP
|
|
If \fIfildes\fP refers to a typed memory object, the result of the
|
|
\fIfdopen\fP() function is unspecified.
|
|
.LP
|
|
The \fIfdopen\fP() function shall preserve the offset maximum previously
|
|
set for the open file description corresponding to
|
|
\fIfildes\fP.
|
|
.SH RETURN VALUE
|
|
.LP
|
|
Upon successful completion, \fIfdopen\fP() shall return a pointer
|
|
to a stream; otherwise, a null pointer shall be returned and
|
|
\fIerrno\fP set to indicate the error.
|
|
.SH ERRORS
|
|
.LP
|
|
The \fIfdopen\fP() function may fail if:
|
|
.TP 7
|
|
.B EBADF
|
|
The \fIfildes\fP argument is not a valid file descriptor.
|
|
.TP 7
|
|
.B EINVAL
|
|
The \fImode\fP argument is not a valid mode.
|
|
.TP 7
|
|
.B EMFILE
|
|
{FOPEN_MAX} streams are currently open in the calling process.
|
|
.TP 7
|
|
.B EMFILE
|
|
{STREAM_MAX} streams are currently open in the calling process.
|
|
.TP 7
|
|
.B ENOMEM
|
|
Insufficient space to allocate a buffer.
|
|
.sp
|
|
.LP
|
|
\fIThe following sections are informative.\fP
|
|
.SH EXAMPLES
|
|
.LP
|
|
None.
|
|
.SH APPLICATION USAGE
|
|
.LP
|
|
File descriptors are obtained from calls like \fIopen\fP(), \fIdup\fP(),
|
|
\fIcreat\fP(), or \fIpipe\fP(), which open files but do not return
|
|
streams.
|
|
.SH RATIONALE
|
|
.LP
|
|
The file descriptor may have been obtained from \fIopen\fP(), \fIcreat\fP(),
|
|
\fIpipe\fP(), \fIdup\fP(), or \fIfcntl\fP(); inherited through \fIfork\fP()
|
|
or \fIexec\fP; or perhaps obtained by
|
|
implementation-defined means, such as the 4.3 BSD \fIsocket\fP() call.
|
|
.LP
|
|
The meanings of the \fImode\fP arguments of \fIfdopen\fP() and \fIfopen\fP()
|
|
differ.
|
|
With \fIfdopen\fP(), open for write (\fIw\fP or \fIw+\fP) does not
|
|
truncate, and append (\fIa\fP or \fIa+\fP) cannot create
|
|
for writing. The \fImode\fP argument formats that include \fIa b\fP
|
|
are allowed for consistency with the ISO\ C standard
|
|
function \fIfopen\fP(). The \fIb\fP has no effect on the resulting
|
|
stream. Although not
|
|
explicitly required by this volume of IEEE\ Std\ 1003.1-2001, a good
|
|
implementation of append (\fIa\fP) mode would cause
|
|
the O_APPEND flag to be set.
|
|
.SH FUTURE DIRECTIONS
|
|
.LP
|
|
None.
|
|
.SH SEE ALSO
|
|
.LP
|
|
\fIInteraction of File Descriptors and Standard I/O Streams\fP , \fIfclose\fP()
|
|
, \fIfopen\fP() , \fIopen\fP() , the Base
|
|
Definitions volume of IEEE\ Std\ 1003.1-2001, \fI<stdio.h>\fP
|
|
.SH COPYRIGHT
|
|
Portions of this text are reprinted and reproduced in electronic form
|
|
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
|
|
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Specifications Issue 6, Copyright (C) 2001-2003 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 .
|