]> rtime.felk.cvut.cz Git - l4.git/blobdiff - l4/pkg/dash/contrib/src/cd.c
Update
[l4.git] / l4 / pkg / dash / contrib / src / cd.c
index 377066468138afcf30de68084cf46750ce94b752..2d9d4b521c9d128b552ae53f6cf1714f247a0a99 100644 (file)
@@ -37,6 +37,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <limits.h>
 
 /*
  * The cd and pwd commands.
@@ -106,7 +107,7 @@ cdcmd(int argc, char **argv)
        if (!dest)
                dest = nullstr;
        if (*dest == '/')
-               goto step7;
+               goto step6;
        if (*dest == '.') {
                c = dest[1];
 dotdot:
@@ -122,13 +123,8 @@ 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)) {
@@ -137,9 +133,15 @@ step7:
 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: