ssttaatt() --  System Call

Find file attributes
#iinncclluuddee <ssyyss/ssttaatt.hh>
iinntt ssttaatt(_f_i_l_e, _s_t_a_t_p_t_r)
cchhaarr *_f_i_l_e; ssttrruucctt ssttaatt *_s_t_a_t_p_t_r;

ssttaatt()  returns  a  structure  that  contains  the attributes  of  a  file,
including protection information, file type, and file size.

_f_i_l_e points to the path name of file.  _s_t_a_t_p_t_r points to a structure of the
type ssttaatt, as  defined in the header file ssttaatt.hh.  For information on ssttaatt,
see the Lexicon entry for ssttaatt.hh.

_E_x_a_m_p_l_e
The following example uses ssttaatt() to print a file's status.

#include <sys/stat.h>
main()
{
    struct stat sbuf;
    int status;

    if (status = stat("/usr/include", &sbuf)) {
        printf("Can't find\n");
        exit(EXIT_FAILURE);
    }

    printf("uid = %d gid = %d\n", sbuf.st_uid, sbuf.st_gid);
}

_S_e_e _A_l_s_o
cchhmmoodd(), cchhoowwnn(), lliibbcc, llss, ooppeenn(), ssttaatt.hh
POSIX Standard, section 5.6.2

_D_i_a_g_n_o_s_t_i_c_s
ssttaatt()  returns -1  if an  error occurs,  e.g., the  file cannot  be found.
Otherwise, it returns zero.

_N_o_t_e_s
ssttaatt() differs  from the  related function  ffssttaatt() mainly in  that ffssttaatt()
accesses  the  file  through  its  descriptor,  which  was  returned  by  a
successful call  to ooppeenn(), whereas  ssttaatt() takes the file's  path name and
opens it before checking its status.

The call

    stat("", &s)

is identical to

    stat(".", &s)

Both calls succeed.  The POSIX Standard forbids the former call -- in fact,
the  POSIX Standard  forbids  the NULL  string  as a  path  name under  any
circumstances; therefore you should never use the former call.
