#include #include #include using namespace std; string Bin(mode_t); int main() { cout << "An int is " << sizeof(int) << " bytes." << endl; cout << "A mode_t is " << sizeof(mode_t) << " bytes." << endl; cout << "S_ISUID = " << Bin(S_ISUID) << endl; cout << "S_ISGID = " << Bin(S_ISGID) << endl; cout << "S_ISVTX = " << Bin(S_ISVTX) << endl; cout << "S_IRUSR = " << Bin(S_IRUSR) << endl; cout << "S_IWUSR = " << Bin(S_IWUSR) << endl; cout << "S_IXUSR = " << Bin(S_IXUSR) << endl; cout << "S_IRGRP = " << Bin(S_IRGRP) << endl; cout << "S_IWGRP = " << Bin(S_IWGRP) << endl; cout << "S_IXGRP = " << Bin(S_IXGRP) << endl; cout << "S_IROTH = " << Bin(S_IROTH) << endl; cout << "S_IWOTH = " << Bin(S_IWOTH) << endl; cout << "S_IXOTH = " << Bin(S_IXOTH) << endl; mode_t flags = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH; cout << "S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH = " << Bin(flags) << endl;; return 0; } string Bin(mode_t flag){ string rv; int k = 0; // we only use the lower 4 hex digits for(int i = 0; i < 12; ++i) { if (k == 3) { rv = ' ' + rv; k = 0; } k++; rv = static_cast(flag%2+'0') + rv; flag /= 2; } return rv; }