Reputation: 81
The function would be something like this.
int GetFilePermission(char* pcUsername, char* pcFilePath)
{
/*return TRUE if 'pcUsername' has read permission on file 'pcFilePath'.*/
}
I don't want to use stat(). Since it would be little bit long. I have to check file's permissions, it's owners and compare them in different combinations. Is there any short and simple way/trick of doing this?
Please help. Thanks in advance.
Upvotes: 1
Views: 3374
Reputation: 188
You can use stat
Prototype for stat
#include <sys/stat.h>
int stat(const char *restrict path, struct stat *restrict buf);
Upvotes: -1
Reputation: 4041
Using the access function we can get the user having a permission. See the man page of access.
int access(const char *pathname, int mode);
If you stat function, you getting all information about that file. In access we have these four only. R_OK, W_OK, X_OK and F_OK.
Using this we can get easily. Return value is zero if success.
R_OK = read permission
W_OK = Write permission
X_OK = Execute permission
F_OK = file is existing.
Upvotes: 2