about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-07-19 19:07:14 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-07-19 19:07:14 +0000
commit606cfb5a5e65c80d88fc90169200cea404c16796 (patch)
tree3912e7287610f77fd37c21fafc2ba6563aacb549 /Src/builtin.c
parent0b8d247f6b433231e26d5930a2ff8d737f424e61 (diff)
downloadzsh-606cfb5a5e65c80d88fc90169200cea404c16796.tar.gz
zsh-606cfb5a5e65c80d88fc90169200cea404c16796.tar.xz
zsh-606cfb5a5e65c80d88fc90169200cea404c16796.zip
27167: add POSIX_CD option to test "." after CDPATH
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 162e7c254..dc39b2a7f 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -945,14 +945,23 @@ cd_do_chdir(char *cnam, char *dest, int hard)
 	return NULL;
     }
 
-    /* if cdpath is being used, check it for . */
-    if (!nocdpath)
+    /*
+     * If cdpath is being used, check it for ".".
+     * Don't bother doing this if POSIXCD is set, we don't
+     * need to know (though it doesn't actually matter).
+     */
+    if (!nocdpath && !isset(POSIXCD))
 	for (pp = cdpath; *pp; pp++)
 	    if (!(*pp)[0] || ((*pp)[0] == '.' && (*pp)[1] == '\0'))
 		hasdot = 1;
-    /* if there is no . in cdpath (or it is not being used), try the directory
-       as-is (i.e. from .) */
-    if (!hasdot) {
+    /*
+     * If 
+     * (- there is no . in cdpath
+     *  - or cdpath is not being used)
+     *  - and the POSIXCD option is not set
+     * try the directory as-is (i.e. from .)
+     */
+    if (!hasdot && !isset(POSIXCD)) {
 	if ((ret = cd_try_chdir(NULL, dest, hard)))
 	    return ret;
 	if (errno != ENOENT)
@@ -971,6 +980,15 @@ cd_do_chdir(char *cnam, char *dest, int hard)
 	    if (errno != ENOENT)
 		eno = errno;
 	}
+    /*
+     * POSIX requires us to check "." after CDPATH rather than before.
+     */
+    if (isset(POSIXCD)) {
+	if ((ret = cd_try_chdir(NULL, dest, hard)))
+	    return ret;
+	if (errno != ENOENT)
+	    eno = errno;
+    }
 
     /* handle the CDABLEVARS option */
     if ((ret = cd_able_vars(dest))) {