title: How to figure out if a file is a link?
body: <p>I have the below code <em>only a part of it is shown here</em> and I am checking if a the type of file.</p>
  
  <pre class="lang-c prettyprint-override"><code>struct stat *buf /* just to show the type buf is*/ 
  
  switch (buf.st_mode &amp; S_IFMT) {
       case S_IFBLK:  printf(" block device\n");            break;
       case S_IFCHR:  printf(" character device\n");        break;
       case S_IFDIR:  printf(" directory\n");               break;
       case S_IFIFO:  printf(" FIFO/pipe\n");               break;
       case S_IFLNK:  printf(" symlink\n");                 break;
       case S_IFREG:  printf(" regular file\n");            break;
       case S_IFSOCK: printf(" socket\n");                  break;
       default:       printf(" unknown?\n");                break;
  }
  </code></pre>
  
  <p>The problem: value of <code>st_mode</code> obtained when I do a <code>printf("\nMode: %d\n",buf.st_mode);</code> the result is 33188.</p>
  
  <p>I tested my program with a regular file type and a symbolic link. In both cases the output was "regular file" i.e the symbolic link case is failing and I fail to understand why?</p>