title: Checking whether a file can be opened using portable C
body: <p>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.</p>
  
  <p>I'm trying to avoid this:</p>
  
  <pre><code>int openable(const char*filename) {
      FILE *f = fopen(filename,"r");
      if (!f)
          return 0; /* openable */
      fclose(f);
      return 1; /* not openable */
  }
  </code></pre>
  
  <p>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. </p>