// 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; } printf("size %ld\n", s.st_size); printf("modes %o\n", s.st_mode); //man 7 inode for macros and flags if (S_ISREG(s.st_mode)) { printf("This is a regular file\n"); } else { printf("This is not a regular file\n"); } if (S_IRUSR & s.st_mode) { printf("Owner can read\n"); } else { printf("Owner can not read\n"); } // Others can execute if (S_IXOTH & s.st_mode) { printf("Others can execute\n"); } else { printf("Others can not execute\n"); } return 0; }