title: How do you determine using stat() whether a file is a symbolic link?
body: <p>I basically have to write a clone of the UNIX ls command for a class, and I've got almost everything working. One thing I can't seem to figure out how to do is check whether a file is a symbolic link or not. From the <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html" rel="noreferrer">man</a> page for <code>stat()</code>, I see that there is a <code>mode_t</code> value defined, <code>S_IFLNK</code>.</p>
  
  <p>This is how I'm trying to check whether a file is a sym-link, with no luck (note, stbuf is the buffer that <code>stat()</code> returned the inode data into):</p>
  
  <pre><code>switch(stbuf.st_mode &amp; S_IFMT){
      case S_IFLNK:
          printf("this is a link\n");
          break;
      case S_IFREG:
          printf("this is not a link\n");
          break;
  }
  </code></pre>
  
  <p>My code ALWAYS prints <code>this is not a link</code> even if it is, and I know for a fact that the said file is a symbolic link since the actual ls command says so, plus I created the sym-link... </p>
  
  <p>Can anyone spot what I may be doing wrong? Thanks for the help!</p>