FSTAT(3)                   POSIX Programmer's Manual                  FSTAT(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
       fstat -- get file status

SSYYNNOOPPSSIISS
       #include <sys/stat.h>

       int fstat(int _f_i_l_d_e_s, struct stat *_b_u_f);

DDEESSCCRRIIPPTTIIOONN
       The _f_s_t_a_t() function shall obtain information about an open file
       associated with the file descriptor _f_i_l_d_e_s, and shall write it to the
       area pointed to by _b_u_f.

       If _f_i_l_d_e_s references a shared memory object, the implementation shall
       update in the ssttaatt structure pointed to by the _b_u_f argument the _s_t___u_i_d,
       _s_t___g_i_d, _s_t___s_i_z_e, and _s_t___m_o_d_e fields, and only the S_IRUSR, S_IWUSR,
       S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits need be
       valid.  The implementation may update other fields and flags.

       If _f_i_l_d_e_s references a typed memory object, the implementation shall
       update in the ssttaatt structure pointed to by the _b_u_f argument the _s_t___u_i_d,
       _s_t___g_i_d, _s_t___s_i_z_e, and _s_t___m_o_d_e fields, and only the S_IRUSR, S_IWUSR,
       S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits need be
       valid. The implementation may update other fields and flags.

       The _b_u_f argument is a pointer to a ssttaatt structure, as defined in
       _<_s_y_s_/_s_t_a_t_._h_>, into which information is placed concerning the file.

       For all other file types defined in this volume of POSIX.1-2017, the
       structure members _s_t___m_o_d_e, _s_t___i_n_o, _s_t___d_e_v, _s_t___u_i_d, _s_t___g_i_d, _s_t___a_t_i_m,
       _s_t___c_t_i_m, and _s_t___m_t_i_m shall have meaningful values and the value of the
       _s_t___n_l_i_n_k member shall be set to the number of links to the file.

       An implementation that provides additional or alternative file access
       control mechanisms may, under implementation-defined conditions, cause
       _f_s_t_a_t() to fail.

       The _f_s_t_a_t() function shall update any time-related fields (as described
       in the Base Definitions volume of POSIX.1-2017, _S_e_c_t_i_o_n _4_._9, _F_i_l_e _T_i_m_e_s
       _U_p_d_a_t_e), before writing into the ssttaatt structure.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
       returned and _e_r_r_n_o set to indicate the error.

EERRRROORRSS
       The _f_s_t_a_t() function shall fail if:

       EEBBAADDFF  The _f_i_l_d_e_s argument is not a valid file descriptor.

       EEIIOO    An I/O error occurred while reading from the file system.

       EEOOVVEERRFFLLOOWW
              The file size in bytes or the number of blocks allocated to the
              file or the file serial number cannot be represented correctly
              in the structure pointed to by _b_u_f.

       The _f_s_t_a_t() function may fail if:

       EEOOVVEERRFFLLOOWW
              One of the values is too large to store into the structure
              pointed to by the _b_u_f argument.

       _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
   OObbttaaiinniinngg FFiillee SSttaattuuss IInnffoorrmmaattiioonn
       The following example shows how to obtain file status information for a
       file named //hhoommee//ccnndd//mmoodd11.  The structure variable _b_u_f_f_e_r is defined
       for the ssttaatt structure. The //hhoommee//ccnndd//mmoodd11 file is opened with
       read/write privileges and is passed to the open file descriptor _f_i_l_d_e_s.


           #include <sys/types.h>
           #include <sys/stat.h>
           #include <fcntl.h>

           struct stat buffer;
           int         status;
           ...
           fildes = open("/home/cnd/mod1", O_RDWR);
           status = fstat(fildes, &buffer);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _f_s_t_a_t_a_t()

       The Base Definitions volume of POSIX.1-2017, _S_e_c_t_i_o_n _4_._9, _F_i_l_e _T_i_m_e_s
       _U_p_d_a_t_e, <<ssyyss__ssttaatt..hh>>, <<ssyyss__ttyyppeess..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                             FSTAT(3)
