07-27-2023, 09:53 AM
I'm trying to understand the flags for the st_mode field of the stat structure of that stat command, but I'm having such a hard time! I found this example [here][1], but I really don't understand this code fragment:
if ( mode & S_IRUSR ) str[1] = 'r'; /* 3 bits for user */
if ( mode & S_IWUSR ) str[2] = 'w';
if ( mode & S_IXUSR ) str[3] = 'x';
if ( mode & S_IRGRP ) str[4] = 'r'; /* 3 bits for group */
if ( mode & S_IWGRP ) str[5] = 'w';
if ( mode & S_IXGRP ) str[6] = 'x';
if ( mode & S_IROTH ) str[7] = 'r'; /* 3 bits for other */
if ( mode & S_IWOTH ) str[8] = 'w';
if ( mode & S_IXOTH ) str[9] = 'x';
I know that "&" is the bitwise AND operator, but nothing else. I don't even know what to ask.
PD: Sorry about the previous questions I asked. I don't know how to mark a question answered or anything like that :(
[1]:
if ( mode & S_IRUSR ) str[1] = 'r'; /* 3 bits for user */
if ( mode & S_IWUSR ) str[2] = 'w';
if ( mode & S_IXUSR ) str[3] = 'x';
if ( mode & S_IRGRP ) str[4] = 'r'; /* 3 bits for group */
if ( mode & S_IWGRP ) str[5] = 'w';
if ( mode & S_IXGRP ) str[6] = 'x';
if ( mode & S_IROTH ) str[7] = 'r'; /* 3 bits for other */
if ( mode & S_IWOTH ) str[8] = 'w';
if ( mode & S_IXOTH ) str[9] = 'x';
I know that "&" is the bitwise AND operator, but nothing else. I don't even know what to ask.
PD: Sorry about the previous questions I asked. I don't know how to mark a question answered or anything like that :(
[1]:
[To see links please register here]