Hello,
I am currently writing a simple shell program for UNIX and I've run into a bit of an issue. So, every file has 9 access permissions: read, write, and execute for user, group, and others. I know the stat struct contains mode_t st_mode which has the file type and access permissions encoded within it. It is easy to recover the file type from the variable because there are macro functions which will return true if the file is of that type. I need to decode the 9 access permissions from this variable though and I can't figure out how. I know there are functions such as umask() and chmod() which will set the access permissions for a current process or given file, but that doesn't really help me in my case. Basically, I just need to be educated on whether there is a function that will tell me the access permissions given the st_mode variable, or any tips to decode the access permissions from the variable itself.
Thank you very much!!!
I am currently writing a simple shell program for UNIX and I've run into a bit of an issue. So, every file has 9 access permissions: read, write, and execute for user, group, and others. I know the stat struct contains mode_t st_mode which has the file type and access permissions encoded within it. It is easy to recover the file type from the variable because there are macro functions which will return true if the file is of that type. I need to decode the 9 access permissions from this variable though and I can't figure out how. I know there are functions such as umask() and chmod() which will set the access permissions for a current process or given file, but that doesn't really help me in my case. Basically, I just need to be educated on whether there is a function that will tell me the access permissions given the st_mode variable, or any tips to decode the access permissions from the variable itself.
Thank you very much!!!
Comment