FILENO(3)                  POSIX Programmer's Manual                 FILENO(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
       fileno -- map a stream pointer to a file descriptor

SSYYNNOOPPSSIISS
       #include <stdio.h>

       int fileno(FILE *_s_t_r_e_a_m);

DDEESSCCRRIIPPTTIIOONN
       The _f_i_l_e_n_o() function shall return the integer file descriptor
       associated with the stream pointed to by _s_t_r_e_a_m.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _f_i_l_e_n_o() shall return the integer value of
       the file descriptor associated with _s_t_r_e_a_m.  Otherwise, the value -1
       shall be returned and _e_r_r_n_o set to indicate the error.

EERRRROORRSS
       The _f_i_l_e_n_o() function shall fail if:

       EEBBAADDFF  The stream is not associated with a file.

       The _f_i_l_e_n_o() function may fail if:

       EEBBAADDFF  The file descriptor underlying _s_t_r_e_a_m is not a valid file
              descriptor.

       _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
       None.

RRAATTIIOONNAALLEE
       Without some specification of which file descriptors are associated
       with these streams, it is impossible for an application to set up the
       streams for another application it starts with _f_o_r_k() and _e_x_e_c.  In
       particular, it would not be possible to write a portable version of the
       _s_h command interpreter (although there may be other constraints that
       would prevent that portability).

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, _d_i_r_f_d(), _f_d_o_p_e_n(), _f_o_p_e_n(), _s_t_d_i_n

       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                            FILENO(3)
