summaryrefslogtreecommitdiff
path: root/bin/sh/cd.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-17 13:15:44 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-17 13:15:44 +0000
commit5231119bf4668c4c03a5dfd18d7d94d5160104e0 (patch)
tree4638f3e07aafe6267a8ef2fe56c11f1abd5d39f1 /bin/sh/cd.c
parenta7d9a9f977ac45e3464248c5a106d10c7cbf022e (diff)
do not treat symbolic links special; from cgd@netbsd.org; netbsd pr#1776
Diffstat (limited to 'bin/sh/cd.c')
-rw-r--r--bin/sh/cd.c107
1 files changed, 5 insertions, 102 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index d3e77689e91..1a275d78949 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -118,124 +118,27 @@ cdcmd(argc, argv)
/*
- * Actually do the chdir. If the name refers to symbolic links, we
- * compute the actual directory name before doing the cd. In an
- * interactive shell, print the directory name if "print" is nonzero
- * or if the name refers to a symbolic link. We also print the name
- * if "/u/logname" was expanded in it, since this is similar to a
- * symbolic link. (The check for this breaks if the user gives the
- * cd command some additional, unused arguments.)
+ * Actually do the chdir. In an interactive shell, print the
+ * directory name if "print" is nonzero.
*/
-#if SYMLINKS == 0
STATIC int
docd(dest, print)
char *dest;
- {
- INTOFF;
- if (chdir(dest) < 0) {
- INTON;
- return -1;
- }
- updatepwd(dest);
- INTON;
- if (print && iflag)
- out1fmt("%s\n", stackblock());
- return 0;
-}
-
-#else
-
-
-
-STATIC int
-docd(dest, print)
- char *dest;
- int print;
{
- register char *p;
- register char *q;
- char *symlink;
- char *component;
- struct stat statb;
- int first;
- int i;
TRACE(("docd(\"%s\", %d) called\n", dest, print));
-
-top:
- cdcomppath = dest;
- STARTSTACKSTR(p);
- if (*dest == '/') {
- STPUTC('/', p);
- cdcomppath++;
- }
- first = 1;
- while ((q = getcomponent()) != NULL) {
- if (q[0] == '\0' || (q[0] == '.' && q[1] == '\0'))
- continue;
- if (! first)
- STPUTC('/', p);
- first = 0;
- component = q;
- while (*q)
- STPUTC(*q++, p);
- if (equal(component, ".."))
- continue;
- STACKSTRNUL(p);
- if (lstat(stackblock(), &statb) < 0)
- error("lstat %s failed", stackblock());
- if (!S_ISLNK(statb.st_mode))
- continue;
-
- /* Hit a symbolic link. We have to start all over again. */
- print = 1;
- STPUTC('\0', p);
- symlink = grabstackstr(p);
- i = (int)statb.st_size + 2; /* 2 for '/' and '\0' */
- if (cdcomppath != NULL)
- i += strlen(cdcomppath);
- p = stalloc(i);
- if (readlink(symlink, p, (int)statb.st_size) < 0) {
- error("readlink %s failed", stackblock());
- }
- if (cdcomppath != NULL) {
- p[(int)statb.st_size] = '/';
- scopy(cdcomppath, p + (int)statb.st_size + 1);
- } else {
- p[(int)statb.st_size] = '\0';
- }
- if (p[0] != '/') { /* relative path name */
- char *r;
- q = r = symlink;
- while (*q) {
- if (*q++ == '/')
- r = q;
- }
- *r = '\0';
- dest = stalloc(strlen(symlink) + strlen(p) + 1);
- scopy(symlink, dest);
- strcat(dest, p);
- } else {
- dest = p;
- }
- goto top;
- }
- STPUTC('\0', p);
- p = grabstackstr(p);
INTOFF;
- if (chdir(p) < 0) {
+ if (chdir(dest) < 0) {
INTON;
return -1;
}
- updatepwd(p);
+ updatepwd(dest);
INTON;
if (print && iflag)
- out1fmt("%s\n", p);
+ out1fmt("%s\n", stackblock());
return 0;
}
-#endif /* SYMLINKS */
-
/*