#include #include #include #include #include using namespace std; static void print_bit(int test, char toPrint){ if(test) cout << toPrint; else cout << '-'; } int main(int argc, char *argv[]){ if(argc != 2){ cerr << "Usage: " << argv[0] << " filename" << endl; return -1; } struct stat info; if(stat(argv[1], &info) < 0){ perror(argv[1]); return -1; } print_bit(info.st_mode & S_IRUSR, 'r'); print_bit(info.st_mode & S_IWUSR, 'w'); print_bit(info.st_mode & S_IXUSR, 'x'); print_bit(info.st_mode & S_IRGRP, 'r'); print_bit(info.st_mode & S_IWGRP, 'w'); print_bit(info.st_mode & S_IXGRP, 'x'); print_bit(info.st_mode & S_IROTH, 'r'); print_bit(info.st_mode & S_IWOTH, 'w'); print_bit(info.st_mode & S_IXOTH, 'x'); cout << endl; return 0; }