#include #include #include #include #include using namespace std; void PrintPerm(mode_t mode, int flag, string phrase) { if (mode & flag) { cout <<"\t\t" << phrase << endl; } return; } void PrintPerms(mode_t mode) { PrintPerm(mode, S_IRUSR, "User Read"); PrintPerm(mode, S_IWUSR, "User Write"); PrintPerm(mode, S_IXUSR, "User Execute"); PrintPerm(mode, S_IRGRP, "Group Read"); PrintPerm(mode, S_IWGRP, "Group Write"); PrintPerm(mode, S_IXGRP, "Group Execute"); PrintPerm(mode, S_IROTH, "Other Read"); PrintPerm(mode, S_IWOTH, "Other Write"); PrintPerm(mode, S_IXOTH, "Other Execute"); return ; } void PrintType(mode_t mode) { cout << "\tIt is a "; if (S_ISREG(mode)) { cout << "regular file"; } else if (S_ISDIR(mode)) { cout << "directory"; } else if (S_ISCHR(mode)) { cout << "character special file"; } else if (S_ISBLK(mode)) { cout << "block special file"; } else if (S_ISFIFO(mode)) { cout << "pipe"; } else if (S_ISSOCK(mode)) { cout << "socket"; } else if (S_ISLNK(mode)) { cout << "symbolic link"; } cout << endl; return; } void PrintReport(string file, const struct stat & buf) { cout <<"Report for " << file << endl; cout <<"\tDevice major: " << major(buf.st_dev) << endl; cout <<"\t minor: " << minor(buf.st_dev) << endl; cout <<"\tInode Number: " << buf.st_ino << endl; cout <<"\tLinks : " << buf.st_nlink << endl; cout <<"\tUID : " << buf.st_uid << endl; cout <<"\tGID : " << buf.st_gid << endl; cout <<"\tSize : " << buf.st_size << endl; cout <<"\tAccess Time : " << ctime(&buf.st_atime); cout <<"\tModify Time : " << ctime(&buf.st_mtime); cout <<"\tStatus Time : " << ctime(&buf.st_ctime); PrintPerms(buf.st_mode); PrintType(buf.st_mode); return; } int main(int argc, char * argv[]) { struct stat buf; int i; for(i=1;i