File:  [MW Coherent from dump] / coherent / a / usr / man / MULTI / stat
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



stat()               General Function (libc)               stat()




Find file attributes

#include <sys/stat.h>
iinntt ssttaatt(_f_i_l_e, _s_t_a_t_p_t_r)
cchhaarr *_f_i_l_e; ssttrruucctt ssttaatt *_s_t_a_t_p_t_r;

stat returns a structure  that contains the attributes of a file,
including protection information, file type, and file size.

file points to the path name of file.  statptr points to a struc-
ture of the type stat, as defined in the header file stat.h.

The following summarizes the structure stat:


struct stat {
    dev_t st_dev;  /* Device */
    ino_t st_ino;  /* i-node number */
    unsigned short st_mode; /* Mode */
    short st_nlink;  /* Link count */
    short st_uid;  /* User id */
    short st_gid;  /* Group id */
    dev_t st_rdev;  /* Real device */
    fsize_t st_size;  /* Size */
    time_t st_atime;  /* Access time */
    time_t st_mtime;  /* Modify time */
    time_t st_ctime;  /* Change time */
};


The following  lists the legal  settings for the  element st_mode
which defines the file's attributes:


         SS_IIFFMMTT     0x0170000    File types
         SS_IIFFRREEGG    0x0100000    Ordinary file
         SS_IIFFDDIIRR    0x0040000    Directory
         SS_IIFFCCHHRR    0x0020000    Character-special file
         SS_IIFFBBLLKK    0x0060000    Block-special file
         SS_IISSUUIIDD    0x0004000    Set user identifier
         SS_IISSGGIIDD    0x0002000    Set group identifier
         SS_IISSVVTTXX    0x0001000    Save text bit
         SS_IIRREEAADD    0x0000400    Owner read permission
         SS_IIWWRRIITTEE   0x0000200    Owner write permission
         SS_IIEEXXEECC    0x0000100    Owner execute permission


st_dev and st_ino together form a unique description of the file.
The former is the device on which the file and its i-node reside,
and the  latter is the  index number of the  file.  st_mode gives
the permission bits,  as outlined above.  st_nlink gives the num-
ber of links to the file.   The user id and group id of the owner
are  st_uid and  st_gid, respectively.   st_rdev, which  is valid
only for special files, holds the major and minor numbers for the


COHERENT Lexicon                                           Page 1




stat()               General Function (libc)               stat()



file.

The entry  st_size gives the size  of the file, in  bytes.  For a
pipe, the size is the number of bytes waiting to be read from the
pipe.

Three entries for each  file give the last occurrences of various
events in  the file's history.  st_atime gives  the time the file
was last read or written to.  st_mtime gives the time of the last
modification, write for  files, create or delete entry for direc-
tories.  st_ctime  gives the last  change to the  attributes, not
including times and size.

***** Example *****

The following example uses stat 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(1);
    }



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


***** Files *****

<sys/stat.h>

***** See Also *****

chmod(), chown(), COHERENT system calls, ls, open()

***** Notes *****

stat differs from the related function fstat mainly in that fstat
accesses the file through its descriptor, which was returned by a
successful call to open,  whereas stat takes the file's path name
and opens it before checking its status.

***** Diagnostics *****

stat  returns -1  if an  error occurs, e.g.,  the file  cannot be


COHERENT Lexicon                                           Page 2




stat()               General Function (libc)               stat()



found.  Otherwise, it returns zero.
























































COHERENT Lexicon                                           Page 3



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.