title: chdir(..) returns 0 for success and changes directory, but outputs "No such file or directory"
body: <p>I'm implementing <code>cd</code> functionality using system calls in a C program that acts as a simple shell, and am having a bit of an issue with directory names. I have a feeling it's trivially string related, but I haven't had any luck so far.</p>
  
  <p>I have a function like the following:</p>
  
  <pre><code>static void parse_args(int argc, char **argv) {
  
      // Special conditions:
      if (strcmp(argv[1], "return") == 0) {
          exit(0);
      }
      else if (strcmp(argv[1], "cd") == 0) {
  
          if (strcmp(argv[2], "mydir") == 0) {
              printf("Directory name is 'mydir'!\n");
          } else {
              printf("Directory name is NOT 'mydir'!\n");
          }
  
          int ret = chdir(argv[2]);
          if (ret == 0) { // success
              printf("Able to change directory.\n");
          } else {
              printf("UNABLE to change directory.\n");
          }
      }
  
      // Handling piping for shell ....
  }
  </code></pre>
  
  <p>I know up front that <code>argv[2]</code> is a string containing my new desired directory.</p>
  
  <p>I wish to <code>cd</code> into an existing directory called <code>mydir</code>, and call <code>changeDirectory</code> with <code>argv[2]</code> equal to <code>"mydir"</code>. However, as you can see, inside <code>changeDirectory</code>, I verify that <code>argv[2]</code> is in fact exactly equal to "mydir".</p>
  
  <p>The results of my simple shell call is:</p>
  
  <pre><code>$&gt; pwd
  /foo/bar
  $&gt; cd mydir
  Directory name is 'mydir'!
  UNABLE to change directory.
  /usr/bin/cd: line 4: cd: mydir: No such file or directory
  $&gt; pwd
  /foo/bar/mydir
  </code></pre>
  
  <p>So it appears the command succeeds, however I don't know why I'm receiving the error message.
  <strong>Interestingly, this error message doesn't occur if I call <code>int ret = chdir("mydir");</code></strong>
  Can I cast/sanitize this parameter somehow? Any pointers would be greatly appreciated. Can I san</p>