title: How to know which file failed during rename?
body: <p>I have a simple example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  
  int main() {
    int result = rename("filea", "doesntexist/fileb");
    if (result != 0) {
      printf("NOOOO %d\n", errno);
    }
    return 0;
  }
  </code></pre>
  
  <p>and I want to distinguish between 2 of the possible failures:</p>
  
  <ol>
  <li>filea doesn't exist</li>
  <li>directory for fileb doesn't exist</li>
  </ol>
  
  <p>but it always returns errno = 2 when either doesn't exist... uhm
  Any ideas how can I approach this?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong> If possible without manually checking if the files exist.</p>
  
  <p><strong>EDIT2:</strong> Not checking if the file exists is a stupid constraint ;) so, I've accepted one of the answers already. Thanks!</p>