// 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[]){ struct stat buf; if(stat("testDir",&buf) < 0){ perror(""); return 1; } printf("size: %ld\n", buf.st_size ); printf("mode %d %o\n",buf.st_mode,buf.st_mode); //man inode for more details if ( buf.st_mode & S_IRUSR){ printf("Owner can read\n"); } else { printf("Owner can't read\n"); } if(S_ISREG(buf.st_mode)){ printf("This is a file\n"); } else { printf("This is not a file\n"); } if(S_ISDIR(buf.st_mode)){ printf("This is a dir\n"); } else { printf("This is not a dir\n"); } return 0; }