Annotation of coherent/a/usr/man/MULTI/stat, revision 1.1.1.1

1.1       root        1: 
                      2: 
                      3: stat()               General Function (libc)               stat()
                      4: 
                      5: 
                      6: 
                      7: 
                      8: Find file attributes
                      9: 
                     10: #include <sys/stat.h>
                     11: iinntt ssttaatt(_f_i_l_e, _s_t_a_t_p_t_r)
                     12: cchhaarr *_f_i_l_e; ssttrruucctt ssttaatt *_s_t_a_t_p_t_r;
                     13: 
                     14: stat returns a structure  that contains the attributes of a file,
                     15: including protection information, file type, and file size.
                     16: 
                     17: file points to the path name of file.  statptr points to a struc-
                     18: ture of the type stat, as defined in the header file stat.h.
                     19: 
                     20: The following summarizes the structure stat:
                     21: 
                     22: 
                     23: struct stat {
                     24:     dev_t st_dev;  /* Device */
                     25:     ino_t st_ino;  /* i-node number */
                     26:     unsigned short st_mode; /* Mode */
                     27:     short st_nlink;  /* Link count */
                     28:     short st_uid;  /* User id */
                     29:     short st_gid;  /* Group id */
                     30:     dev_t st_rdev;  /* Real device */
                     31:     fsize_t st_size;  /* Size */
                     32:     time_t st_atime;  /* Access time */
                     33:     time_t st_mtime;  /* Modify time */
                     34:     time_t st_ctime;  /* Change time */
                     35: };
                     36: 
                     37: 
                     38: The following  lists the legal  settings for the  element st_mode
                     39: which defines the file's attributes:
                     40: 
                     41: 
                     42:          SS_IIFFMMTT     0x0170000    File types
                     43:          SS_IIFFRREEGG    0x0100000    Ordinary file
                     44:          SS_IIFFDDIIRR    0x0040000    Directory
                     45:          SS_IIFFCCHHRR    0x0020000    Character-special file
                     46:          SS_IIFFBBLLKK    0x0060000    Block-special file
                     47:          SS_IISSUUIIDD    0x0004000    Set user identifier
                     48:          SS_IISSGGIIDD    0x0002000    Set group identifier
                     49:          SS_IISSVVTTXX    0x0001000    Save text bit
                     50:          SS_IIRREEAADD    0x0000400    Owner read permission
                     51:          SS_IIWWRRIITTEE   0x0000200    Owner write permission
                     52:          SS_IIEEXXEECC    0x0000100    Owner execute permission
                     53: 
                     54: 
                     55: st_dev and st_ino together form a unique description of the file.
                     56: The former is the device on which the file and its i-node reside,
                     57: and the  latter is the  index number of the  file.  st_mode gives
                     58: the permission bits,  as outlined above.  st_nlink gives the num-
                     59: ber of links to the file.   The user id and group id of the owner
                     60: are  st_uid and  st_gid, respectively.   st_rdev, which  is valid
                     61: only for special files, holds the major and minor numbers for the
                     62: 
                     63: 
                     64: COHERENT Lexicon                                           Page 1
                     65: 
                     66: 
                     67: 
                     68: 
                     69: stat()               General Function (libc)               stat()
                     70: 
                     71: 
                     72: 
                     73: file.
                     74: 
                     75: The entry  st_size gives the size  of the file, in  bytes.  For a
                     76: pipe, the size is the number of bytes waiting to be read from the
                     77: pipe.
                     78: 
                     79: Three entries for each  file give the last occurrences of various
                     80: events in  the file's history.  st_atime gives  the time the file
                     81: was last read or written to.  st_mtime gives the time of the last
                     82: modification, write for  files, create or delete entry for direc-
                     83: tories.  st_ctime  gives the last  change to the  attributes, not
                     84: including times and size.
                     85: 
                     86: ***** Example *****
                     87: 
                     88: The following example uses stat to print a file's status.
                     89: 
                     90: 
                     91: #include <sys/stat.h>
                     92: main()
                     93: {
                     94:     struct stat sbuf;
                     95:     int status;
                     96: 
                     97: 
                     98: 
                     99:     if(status = stat("/usr/include", &sbuf)) {
                    100:                printf("Can't find\n");
                    101:                exit(1);
                    102:     }
                    103: 
                    104: 
                    105: 
                    106:     printf("uid = %d gid = %d\n", sbuf.st_uid, sbuf.st_gid);
                    107: }
                    108: 
                    109: 
                    110: ***** Files *****
                    111: 
                    112: <sys/stat.h>
                    113: 
                    114: ***** See Also *****
                    115: 
                    116: chmod(), chown(), COHERENT system calls, ls, open()
                    117: 
                    118: ***** Notes *****
                    119: 
                    120: stat differs from the related function fstat mainly in that fstat
                    121: accesses the file through its descriptor, which was returned by a
                    122: successful call to open,  whereas stat takes the file's path name
                    123: and opens it before checking its status.
                    124: 
                    125: ***** Diagnostics *****
                    126: 
                    127: stat  returns -1  if an  error occurs, e.g.,  the file  cannot be
                    128: 
                    129: 
                    130: COHERENT Lexicon                                           Page 2
                    131: 
                    132: 
                    133: 
                    134: 
                    135: stat()               General Function (libc)               stat()
                    136: 
                    137: 
                    138: 
                    139: found.  Otherwise, it returns zero.
                    140: 
                    141: 
                    142: 
                    143: 
                    144: 
                    145: 
                    146: 
                    147: 
                    148: 
                    149: 
                    150: 
                    151: 
                    152: 
                    153: 
                    154: 
                    155: 
                    156: 
                    157: 
                    158: 
                    159: 
                    160: 
                    161: 
                    162: 
                    163: 
                    164: 
                    165: 
                    166: 
                    167: 
                    168: 
                    169: 
                    170: 
                    171: 
                    172: 
                    173: 
                    174: 
                    175: 
                    176: 
                    177: 
                    178: 
                    179: 
                    180: 
                    181: 
                    182: 
                    183: 
                    184: 
                    185: 
                    186: 
                    187: 
                    188: 
                    189: 
                    190: 
                    191: 
                    192: 
                    193: 
                    194: 
                    195: 
                    196: COHERENT Lexicon                                           Page 3
                    197: 
                    198: 

unix.superglobalmegacorp.com

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