This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

B19.1: chdir bug (NT 4.0)

I've found a bug that affects chdir() when trying to change to the root of
a self-mounted drives.  I've attached an example program that demonstrates
the problem.

For discussion, consider the following directory structure:
  +-- foo
       +-- bar

If my example program is run from //G/ with the command chdir_test foo, it
will  change to the directory foo, and then try to change back to //G/.
chdir will return a success result code, but the current directory doesn't
get changed.  If it is run from //G/foo with the command chdir_test bar, it
will change to //G/foo/bar and then change back to /G/foo as expected.

I searched the FAQ and mailing list archives, and didn't see any mention of
this particular problem.  I don't have the sources, so I haven't been able
to see if I could identify the cause of the problem.

- Tim Taylor
- Tim
 * This program tests the chdir function in CygWin32 B19.1.
 * This function fails to work when invoked with a directory name from a
 * unmounted drives root.  It works fine if invoked for a directory that is a
 * subdirectory on the same drive.
 * Here's the situation:
 *   //G/
 *     |
 *     +-- foo
 *          |
 *          +-- bar
 * When this program is invoked, it will print out the name of the directory
 * it was invoked from, it will then chdir() to the directory provided on the
 * command line.  Next it will use getcwd() and print out the current
 * directory.  It will then use chdir() again to move back to the directory it
 * started from, and then use getcwd() to print out the directory that is now
 * current.
 * Using the directory tree shown above, the output will look like:
 * Invoked from //G/ with chdir_test foo
 * -------------------------------------
 * Starting directory: //G
 * chdir(foo) succeeded.
 * Current dir: //G/foo
 * chdir(//G) succeeded.
 * Current dir: //G/foo
 *   **** Error - current dir is not what it should be.
 * Invoked from //G/foo with chdir_test bar
 * ----------------------------------------
 * Starting directory: //G/foo
 * chdir(bar) succeeded.
 * Current dir: //G/foo/bar
 * chdir(//G/foo) succeeded.
 * Current dir: //g/foo
 *   current dir is corrent.
 * Author: Tim Taylor (
 *   Date: 26 Aug. 1998

#include <stdio.h>
#include <sys/errno.h>

void print_usage(void) {
  printf("Usage: stat_test dir_name\n\n");
  printf("  dir_name should be a directory in the current directory\n");

int main(int argc, char **argv) {
  char *dirName, origDir[256], curDir[256];
  if(argc < 2) {

  dirName = argv[1];
  getcwd(origDir, sizeof(curDir));
  printf("Starting directory: %s\n", origDir);
  if(chdir(dirName) < 0) {
    printf("chdir(%s) failed with error code: %d\n", dirName, errno);
  } else {
    printf("chdir(%s) succeeded.\n", dirName);
  getcwd(curDir, sizeof(curDir));
  printf("Current dir: %s\n", curDir);
  if(chdir(origDir) < 0) {
    printf("chdir(%s) failed with error code: %d\n", origDir, errno);
  } else {
    printf("chdir(%s) succeeded.\n", origDir);
  getcwd(curDir, sizeof(curDir));
  printf("Current dir: %s\n", curDir);
  if(strcmp(origDir, curDir))
    printf("  **** Error - current dir is not what it should be.\n");
    printf("  current dir is corrent.\n");

 Timothy L. Taylor                        Internet:
 Lead Software Systems Engineer              Voice: (781) 271-8770
 The Mitre Corporation                         Fax: (781) 271-7231
 202 Burlington Rd.                      Mail Stop: B295
 Bedford, Massachusetts 01730-1420

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]