perror help

I can't figure out how I can use perror to show an error if a file already has read permission? Any input will help. Thank You.
1
2
3
 printf( (fileStat.st_mode & S_IRUSR) ? "r" : "-");
        if( (fileStat.st_mode & S_IRUSR)== -1)
                perror("you goofed");
Is this what you want to do?

1
2
3
printf( (fileStat.st_mode & S_IRUSR) ? "r" : "-");
if( (fileStat.st_mode & S_IRUSR)== 0)
    perror("you goofed");
You're not using perror correctly.
http://www.cplusplus.com/reference/cstdio/perror/

perror relies on the global errno to be set. perror will supply error text appropriate to the value of errno with a prefix that you provide. Simply executing an if statement, will not cause the runtime to set errno.


Last edited on
Topic archived. No new replies allowed.