Public domain
#include <stdio.h>
#include <unistd.h>
#define FILE "/etc/resolv.conf"
int main()
{
if(access(FILE, F_OK) == 0)
printf("%s is exist.\n", FILE);
if(access(FILE, R_OK) == 0)
printf("%s is readable.\n", FILE);
if(access(FILE, W_OK) == 0)
printf("%s is writable.\n", FILE);
if(access(FILE, X_OK) == 0)
printf("%s is executable.\n", FILE);
if(access(FILE, R_OK | W_OK) == 0)
printf("%s is readable AND writable.\n", FILE);
return 0;
}
BY: Pejman Moghadam
TAG: permission, existence
DATE: 2012-02-25 14:55:54