title: Determining if two file paths point to same file under Linux / C?
body: <p>Under Linux, I have two file paths A and B:</p>
  
  <pre><code>const char* A = ...;
  const char* B = ...;
  </code></pre>
  
  <p>I now want to determine, should I <code>open(2)</code> them both...</p>
  
  <pre><code>int fda = open(A, ...);
  int fdb = open(B, ...);
  </code></pre>
  
  <p>...will I get two filehandles open to the same file in the filesystem?</p>
  
  <p>To determine this I thought of <code>stat(2)</code>:</p>
  
  <pre><code>struct stat
  {
      dev_t st_dev;
      ino_t st_ino;
      ...
  }
  </code></pre>
  
  <p>Something like (pseudo-code):</p>
  
  <pre><code>bool IsSameFile(const char* sA, const char* sB)
  {
      stat A = stat(sA);
      stat B = stat(sB);
  
      return A.st_dev == B.st_dev &amp;&amp; A.st_ino == B.st_ino;
  }
  </code></pre>
  
  <p>Are there any cases where A and B are the same file but <code>IsSameFile</code> would return false?</p>
  
  <p>Are there any cases where A and B are different files but <code>IsSameFile</code> would return true?</p>
  
  <p>Is there a better way to do what I'm trying to do?</p>