adityakavoor
February 20th, 2008, 06:26 PM
Here is my simple C program that checks whether a file has write permission or not .
#include<stdio.h>
#include<errno.h>
#include<unistd.h>
#include<sys/types.h>
#include<fcntl.h>
int main(int argc,char *argv[])
{
int fd;
fd = open(argv[1],O_WRONLY,0);
if(fd == -1)
{
if(errno == EACCESS)
printf("No permission\n");
else if(errno == ENOENT)
printf("File doesnt exist\n");
}
else printf("File opened and is writable\n");
}
There seems to be no problem with ENOENT .
But <errno.h> doesnt recognise EACCESS and I get the following error during compilation. :( :(
In function ‘main’:
error: ‘EACCESS’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
What am I missing here ??? :confused:
#include<stdio.h>
#include<errno.h>
#include<unistd.h>
#include<sys/types.h>
#include<fcntl.h>
int main(int argc,char *argv[])
{
int fd;
fd = open(argv[1],O_WRONLY,0);
if(fd == -1)
{
if(errno == EACCESS)
printf("No permission\n");
else if(errno == ENOENT)
printf("File doesnt exist\n");
}
else printf("File opened and is writable\n");
}
There seems to be no problem with ENOENT .
But <errno.h> doesnt recognise EACCESS and I get the following error during compilation. :( :(
In function ‘main’:
error: ‘EACCESS’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
What am I missing here ??? :confused: