Created
November 15, 2015 04:02
-
-
Save zsrinivas/bab0ae824bd526f17f0e to your computer and use it in GitHub Desktop.
setItemModes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setItemModes(const char* itemname, char* modes) { | |
struct stat info; | |
stat(itemname, &info); | |
mode_t mode = info.st_mode; | |
strcpy(modes, "----------"); | |
if ( S_ISDIR(mode) ) modes[0] = 'd'; | |
if ( S_ISCHR(mode) ) modes[0] = 'c'; | |
if ( S_ISBLK(mode) ) modes[0] = 'b'; | |
if ( mode & S_IRUSR ) modes[1] = 'r'; | |
if ( mode & S_IWUSR ) modes[2] = 'w'; | |
if ( mode & S_IXUSR ) modes[3] = 'x'; | |
if ( mode & S_IRGRP ) modes[4] = 'r'; | |
if ( mode & S_IWGRP ) modes[5] = 'w'; | |
if ( mode & S_IXGRP ) modes[6] = 'x'; | |
if ( mode & S_IROTH ) modes[7] = 'r'; | |
if ( mode & S_IWOTH ) modes[8] = 'w'; | |
if ( mode & S_IXOTH ) modes[9] = 'x'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment