PDA

View Full Version : [SOLVED] < errno.h > -- Help needed



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:

lnostdal
February 20th, 2008, 06:39 PM
EACCES

..see man 2 open .. also see man 2 perror .. you can take advantage of that when printing error messages

adityakavoor
February 20th, 2008, 06:41 PM
changing to EACCES worked :popcorn:

ruy_lopez
February 20th, 2008, 07:06 PM
see also:


man strerror

Just be careful errno doesn't change between catching the error and printing the associated string.

adityakavoor
February 20th, 2008, 08:46 PM
see also:


man strerror

Just be careful errno doesn't change between catching the error and printing the associated string.

No manual entry for strerror

DoktorSeven
February 20th, 2008, 10:53 PM
No manual entry for strerror

sudo apt-get install manpages-dev

adityakavoor
February 21st, 2008, 11:01 AM
sudo apt-get install manpages-dev

Thanks. It was useful.