I'd like to perform a quick check whether or not a file can be opened. It should be written in portable C, or at least to work on Win32 and POSIX systems. #ifdefs are acceptable.
I'm trying to avoid this:
int openable(const char*filename) {
FILE *f = fopen(filename,"r");
if (!f)
return 0; /* openable */
fclose(f);
return 1; /* not openable */
}
From what I can tell stat(), in its simplest form, can be used to check if file exists, but not to check if it's actually openable.