I can get the real and effective UIDs of the current user, so, given some file or directory, how can I use these UIDs to check the rights,
rwx, that this specific user has for accessing/modifying the file or directory?
Thanks to roaima's comment I came up with the following:
//snip... #include <fcntl.h> #include <unistd.h> ... bool bcanR, bcanW, bcanX; //'fullpath' is to file or directory.. bcanR=(faccessat(0, fullpath, R_OK, AT_EACCESS)==0); bcanW=(faccessat(0, fullpath, W_OK, AT_EACCESS)==0); bcanX=(faccessat(0, fullpath, X_OK, AT_EACCESS)==0); ... //snip
which answers my need since it uses effective UID to check permissions.
Also based on this answer need to keep in mind that changing the permissions (using
chmod) can only be done by the owner or root.