perror help
Jan 26, 2015 at 11:02pm UTC
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" );
Jan 27, 2015 at 12:16am UTC
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" );
Jan 27, 2015 at 12:18am UTC
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 Jan 27, 2015 at 12:18am UTC
Topic archived. No new replies allowed.