#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
/*
* The cd and pwd commands.
if (!dest)
dest = nullstr;
if (*dest == '/')
- goto step7;
+ goto step6;
if (*dest == '.') {
c = dest[1];
dotdot:
}
if (!*dest)
dest = ".";
- if (!(path = bltinlookup("CDPATH"))) {
-step6:
-step7:
- p = dest;
- goto docd;
- }
- do {
+ path = bltinlookup("CDPATH");
+ while (path) {
c = *path;
p = padvance(&path, dest);
if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
docd:
if (!docd(p, flags))
goto out;
- break;
+ goto err;
}
- } while (path);
+ }
+
+step6:
+ p = dest;
+ goto docd;
+
+err:
sh_error("can't cd to %s", dest);
/* NOTREACHED */
out: