// An example showing how to use stat and // extract information about the file type // and access permissions #include #include #include #include #include #include int main(int argc, char* argv[]){ if( argc < 2){ fprintf(stderr,"Usage...\n"); return 1; } //man 2 stat for system call //man 3 stat for struct struct stat s; if(stat(argv[1],&s) < 0){ perror(""); return 1; } // What is the size of the file? printf("File size : %d\n", s.st_size); // What are the permisiions for the file? printf("File permissions are: %o\n", s.st_mode); //man 7 inode for macros and flags //Is this a regular file - MACROS if (S_ISREG(s.st_mode)) { printf("This is a regular file\n"); } else { printf("This is not a regular file\n"); } // Owner can read - FLAGs if (S_IRUSR & s.st_mode) { printf("Owner can read\n"); } else { printf("Owner can not read\n"); } return 0; }