For homework I have to write a C program and one of the things it has to do is check to see a file exists and if it is executable by the owner.
Using (stat(path[j], &sb) >= 0
I'm able to see if the file indicated by path[j] exists.
I've looked through man pages, a lot of questions and answers on stackoverflow, and several websites but I'm not able to wrap my head around exactly how to check if a file is executable using stat.
I thought it would be as simple as ((stat(path[j], &sb) >= 0) && (sb.st_mode > 0) && (S_IEXEC)
but as far as I can tell by testing it, it seems to ignore the fact that these files aren't executable.
I think that perhaps stat doesn't work the way I think it does. Assuming I use stat, how can I go about fixing this?