Wrong reason was reported for cd'ing to a directory with no permission
[unix-history] / usr / src / bin / csh / dir.c
index 14f61c4..9907f25 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)dir.c      5.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)dir.c      5.12 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -15,6 +15,11 @@ static char sccsid[] = "@(#)dir.c    5.9 (Berkeley) %G%";
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#if __STDC__
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
 
 #include "csh.h"
 #include "dir.h"
 
 #include "csh.h"
 #include "dir.h"
@@ -386,6 +391,7 @@ dfollow(cp)
     register Char *dp;
     struct varent *c;
     char    ebuf[MAXPATHLEN];
     register Char *dp;
     struct varent *c;
     char    ebuf[MAXPATHLEN];
+    int serrno;
 
     cp = globone(cp, G_ERROR);
     /*
 
     cp = globone(cp, G_ERROR);
     /*
@@ -400,6 +406,7 @@ dfollow(cp)
        xfree((ptr_t) dp);
        if (chdir(short2str(cp)) >= 0)
            return dgoto(cp);
        xfree((ptr_t) dp);
        if (chdir(short2str(cp)) >= 0)
            return dgoto(cp);
+       serrno = errno;
     }
 
     if (cp[0] != '/' && !prefix(STRdotsl, cp) && !prefix(STRdotdotsl, cp)
     }
 
     if (cp[0] != '/' && !prefix(STRdotsl, cp) && !prefix(STRdotdotsl, cp)
@@ -429,7 +436,7 @@ dfollow(cp)
     }
     (void) strcpy(ebuf, short2str(cp));
     xfree((ptr_t) cp);
     }
     (void) strcpy(ebuf, short2str(cp));
     xfree((ptr_t) cp);
-    stderror(ERR_SYSTEM, ebuf, strerror(errno));
+    stderror(ERR_SYSTEM, ebuf, strerror(serrno));
     return (NULL);
 }
 
     return (NULL);
 }
 
@@ -805,7 +812,7 @@ dcanon(cp, p)
     /*
      * See if we're not in a subdir of STRhome
      */
     /*
      * See if we're not in a subdir of STRhome
      */
-    if (p1 && *p1 &&
+    if (p1 && *p1 == '/' &&
        (Strncmp(p1, cp, cc) != 0 || (cp[cc] != '/' && cp[cc] != '\0'))) {
        static ino_t home_ino = -1;
        static dev_t home_dev = -1;
        (Strncmp(p1, cp, cc) != 0 || (cp[cc] != '/' && cp[cc] != '\0'))) {
        static ino_t home_ino = -1;
        static dev_t home_dev = -1;