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("r");
else
printf("-");
}else
printf("Can''t stat %s\n", argv[1]);
}else
printf("Usage:%s file_name\n",argv[0]);
Have I interpreted this correctly, or am I completly wrong?
Mode bits for access permission
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.
http://www.gnu.org/manual/glibc-2.2.3/html_node/libc_278.html#SEC287
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 "-".
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.
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.
Ok you just completly confused me then, in unix permissions are set for example as follows
-rwxrwxrwx (for a file)
or
drwxrwxrwx (for a directory)
Out of the flags from this document I have determined this
- S_IRUSR S_IWUSR S_IXUSR S_IRGRP S_IWGRP S_IXGRP S_IROTH S_IWOTH S_IXOTH
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.
-rwxrwxrwx (for a file)
or
drwxrwxrwx (for a directory)
Out of the flags from this document I have determined this
- S_IRUSR S_IWUSR S_IXUSR S_IRGRP S_IWGRP S_IXGRP S_IROTH S_IWOTH S_IXOTH
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement