title: dirname() in C: is the manual wrong?
body: <p>Citing <a href="http://linux.die.net/man/3/dirname" rel="nofollow">the manual</a> here:</p>
  
  <blockquote>
    <p>The  functions  dirname() and basename() break a null-terminated
    pathname string into directory and filename components.  In the usual
    case, <strong>dirname() returns the string up to, but not including, the final
    '/'</strong>, and basename() returns the component following the final '/'. 
    Trailing '/' characters are not counted as part of the pathname.</p>
  </blockquote>
  
  <p>And later on, you have this little table:</p>
  
  <pre><code>path         dirname    basename
  "/usr/lib"    "/usr"    "lib"
  "/usr/"       "/"       "usr"        // wat?
  "usr"         "."       "usr"
  "/"           "/"       "/"
  "."           "."       "."
  ".."          "."       ".."
  </code></pre>
  
  <p>Why is <code>dirname( "/usr/")</code> returning <code>"/"</code> and not <code>"/usr"</code> ?<br>
  The sentence in the manual tells me I should get <code>/usr</code> as a result.<br>
  I tested the actual result in a dummy program and it behaves just like the manual says.  </p>
  
  <pre><code>#include &lt;libgen.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char const *argv[])
  {
      const char *mydir="/usr/";
      char *dummy  = strdup( mydir );
      char *dummy2 = strdup( mydir );
  
      char *dname = dirname( dummy );
      char *bname = basename( dummy2 );
  
  
      printf("mydir: '%s', dname: '%s', bname: '%s'\n", mydir, dname, bname);
  
      free( dummy );
      free( dummy2 );
  
      return 0;
  }
  
  
  $ ./test  
  mydir: '/usr/', dname: '/', bname: 'usr'
  </code></pre>
  
  <p>Now, what I would expect would be:</p>
  
  <pre><code>path         dirname    basename
  "/usr/"       "/usr"       ""        // more consistent?
  </code></pre>
  
  <p>So.. anybody understands what's going on here?</p>