title: Check if input file is a valid file in C
body: <p>I am trying to open a file in c using open() and I need to check that the file is a regular file (it can't be a directory or a block file). Every time I run open() my returned file discriptor is 3 - even when I don't enter a valid filename! </p>
  
  <p>Here's what I have</p>
  
  <pre><code>/*
  * Checks to see if the given filename is 
  * a valid file
  */
  int isValidFile(char *filename) {
      // We assume argv[1] is a filename to open
      int fd;
      fd = open(filename,O_RDWR|O_CREAT,0644);
      printf("fd = %d\n", fd);
      /* fopen returns 0, the NULL pointer, on failure */
  
  }
  </code></pre>
  
  <p>Can anyone tell me how to validate input files?
  Thanks!</p>