This topic is now archived and is closed to further replies.

Mode bits for access permission

This topic is 5776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to figure out stat.h, the part where the mode bits are set for the file access permissions. I have found the following information. Ok i''ve written my interpretation of the mode bits. Basically what the following code snippet should do is check if the bit representing read permissions for the user is set, then it should print an "r" else it will print "-".
struct stat sbuf;
mode_t mode;

if(argv[1] !=''\0''){
   if(lstat(argv[1],&sbuf) != -1){
      mode = sbuf.st_mode;
      if(mode == S_IRUSR)
      printf("Can''t stat %s\n", argv[1]);
   printf("Usage:%s file_name\n",argv[0]);    
Have I interpreted this correctly, or am I completly wrong?

Share this post

Link to post
Share on other sites
To see wether is a flag set within a constant grout such (i.e. VK_ESCAPE + VK_ENTER) you have to do this:
if (Key & VK_ESCAPE) // ESCAPE key is pressed
if (Key & VK_ENTER) // ENTER key is pressed.
you should do this to work with any kind of bitwise flags.

Share this post

Link to post
Share on other sites
Ok you just completly confused me then, in unix permissions are set for example as follows

-rwxrwxrwx (for a file)


drwxrwxrwx (for a directory)

Out of the flags from this document I have determined this


Those are the flags for user,group and others. I couldn''t figure out the flag for the directory. I really didn''t understand what u were saying can u clarify it for me possibly under this context.

Share this post

Link to post
Share on other sites