// broken attempt to implement cd // chdir() affects only this process and any it runs // this versions prints out the current working // directory while this process is running #include #include #include int main(int argc, char *argv[]) { if (argc > 1 && chdir(argv[1]) != 0) { perror("chdir"); return 1; } char pathname[PATH_MAX]; if (getcwd(pathname, sizeof pathname) == NULL) { perror("getcwd"); return 1; } printf("getcwd() returned %s\n", pathname); return 0; }