Just want to make sure if I'm right about this, would it be justified to say that for some:
struct stat fStat;
given that the argument passed in the terminal will be either a file or directory, can I state that
if((fileStat.st_mode & S_IRWXU) == true)
then the user is also the owner of the file? What about if I'm checking a directory outside of the directory I'm currently in, would this still hold valid?(granted that it's correct)
New to all this, an explanation would be appreciated!
No. All that confirms is that the file has certain permissions for the owner, it does not state that you are actually the owner.
There's another field in the stat
structure called st_uid
which is the user ID of the owner. You need to compare that against your own user ID (see the getuid()
function).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.