FDOPEN(3)                  POSIX Programmer's Manual                 FDOPEN(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       fdopen -- associate a stream with a file descriptor

SSYYNNOOPPSSIISS
       #include <stdio.h>

       FILE *fdopen(int _f_i_l_d_e_s, const char *_m_o_d_e);

DDEESSCCRRIIPPTTIIOONN
       The _f_d_o_p_e_n() function shall associate a stream with a file descriptor.

       The _m_o_d_e argument is a character string having one of the following
       values:

       _r or _r_b       Open a file for reading.

       _w or _w_b       Open a file for writing.

       _a or _a_b       Open a file for writing at end-of-file.

       _r+ or _r_b+ or _r+_b
                     Open a file for update (reading and writing).

       _w+ or _w_b+ or _w+_b
                     Open a file for update (reading and writing).

       _a+ or _a_b+ or _a+_b
                     Open a file for update (reading and writing) at end-of-
                     file.

       The meaning of these flags is exactly as specified in _f_o_p_e_n(), except
       that modes beginning with _w shall not cause truncation of the file.

       Additional values for the _m_o_d_e argument may be supported by an
       implementation.

       The application shall ensure that the mode of the stream as expressed
       by the _m_o_d_e argument is allowed by the file access mode of the open
       file description to which _f_i_l_d_e_s 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.

       The error and end-of-file indicators for the stream shall be cleared.
       The _f_d_o_p_e_n() function may cause the last data access timestamp of the
       underlying file to be marked for update.

       If _f_i_l_d_e_s refers to a shared memory object, the result of the _f_d_o_p_e_n()
       function is unspecified.

       If _f_i_l_d_e_s refers to a typed memory object, the result of the _f_d_o_p_e_n()
       function is unspecified.

       The _f_d_o_p_e_n() function shall preserve the offset maximum previously set
       for the open file description corresponding to _f_i_l_d_e_s.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _f_d_o_p_e_n() shall return a pointer to a
       stream; otherwise, a null pointer shall be returned and _e_r_r_n_o set to
       indicate the error.

EERRRROORRSS
       The _f_d_o_p_e_n() function shall fail if:

       EEMMFFIILLEE {STREAM_MAX} streams are currently open in the calling process.

       The _f_d_o_p_e_n() function may fail if:

       EEBBAADDFF  The _f_i_l_d_e_s argument is not a valid file descriptor.

       EEIINNVVAALL The _m_o_d_e argument is not a valid mode.

       EEMMFFIILLEE {FOPEN_MAX} streams are currently open in the calling process.

       EENNOOMMEEMM Insufficient space to allocate a buffer.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       File descriptors are obtained from calls like _o_p_e_n(), _d_u_p(), _c_r_e_a_t(),
       or _p_i_p_e(), which open files but do not return streams.

RRAATTIIOONNAALLEE
       The file descriptor may have been obtained from _o_p_e_n(), _c_r_e_a_t(),
       _p_i_p_e(), _d_u_p(), _f_c_n_t_l(), or _s_o_c_k_e_t(); inherited through _f_o_r_k(),
       _p_o_s_i_x___s_p_a_w_n(), or _e_x_e_c; or perhaps obtained by other means.

       The meanings of the _m_o_d_e arguments of _f_d_o_p_e_n() and _f_o_p_e_n() differ. With
       _f_d_o_p_e_n(), open for write (_w or _w_+) does not truncate, and append (_a or
       _a_+) cannot create for writing. The _m_o_d_e argument formats that include a
       _b are allowed for consistency with the ISO C standard function _f_o_p_e_n().
       The _b has no effect on the resulting stream. Although not explicitly
       required by this volume of POSIX.1-2017, a good implementation of
       append (_a) mode would cause the O_APPEND flag to be set.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._5_._1, _I_n_t_e_r_a_c_t_i_o_n _o_f _F_i_l_e _D_e_s_c_r_i_p_t_o_r_s _a_n_d _S_t_a_n_d_a_r_d _I_/_O
       _S_t_r_e_a_m_s, _f_c_l_o_s_e(), _f_m_e_m_o_p_e_n(), _f_o_p_e_n(), _o_p_e_n(), _o_p_e_n___m_e_m_s_t_r_e_a_m(),
       _p_o_s_i_x___s_p_a_w_n(), _s_o_c_k_e_t()

       The Base Definitions volume of POSIX.1-2017, <<ssttddiioo..hh>>

CCOOPPYYRRIIGGHHTT
       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 .

       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 .



IEEE/The Open Group                  2017                            FDOPEN(3)
