M
MS
I need to establish whether the user running my program (a command line
tool) has read permission of the files they entered on the command line.
The code was using stat() and then checking st_mode with S_IRUSR (read
permission, owner) but I've now realized that just checks whether the
owner has read permission and not whether the user running the program
is the owner and has read permission. So if the permissions of a file are:
rw------- and it's owned by root, and the user is NOT root, but the user
has read permission of the directory where the file is then S_IRUSR will
be set - the owner has read permission.
How do I tell if the user running the program has read permission of the
file?
Note: I realize I could just fopen() the file and if that fails then I
have my answer but that seems like a rather inelegant solution.
Thanks.
tool) has read permission of the files they entered on the command line.
The code was using stat() and then checking st_mode with S_IRUSR (read
permission, owner) but I've now realized that just checks whether the
owner has read permission and not whether the user running the program
is the owner and has read permission. So if the permissions of a file are:
rw------- and it's owned by root, and the user is NOT root, but the user
has read permission of the directory where the file is then S_IRUSR will
be set - the owner has read permission.
How do I tell if the user running the program has read permission of the
file?
Note: I realize I could just fopen() the file and if that fails then I
have my answer but that seems like a rather inelegant solution.
Thanks.