summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/sh/cd.c7
-rw-r--r--tools/regression/bin/sh/builtins/cd8.026
2 files changed, 32 insertions, 1 deletions
diff --git a/bin/sh/cd.c b/bin/sh/cd.c
index 6fb1039..1330c85 100644
--- a/bin/sh/cd.c
+++ b/bin/sh/cd.c
@@ -130,7 +130,12 @@ cdcmd(int argc, char **argv)
(path = bltinlookup("CDPATH", 1)) == NULL)
path = nullstr;
while ((p = padvance(&path, dest)) != NULL) {
- if (stat(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
+ if (stat(p, &statb) < 0) {
+ if (errno != ENOENT)
+ errno1 = errno;
+ } else if (!S_ISDIR(statb.st_mode))
+ errno1 = ENOTDIR;
+ else {
if (!print) {
/*
* XXX - rethink
diff --git a/tools/regression/bin/sh/builtins/cd8.0 b/tools/regression/bin/sh/builtins/cd8.0
new file mode 100644
index 0000000..a68f77f
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/cd8.0
@@ -0,0 +1,26 @@
+# $FreeBSD$
+
+# The exact wording of the error message is not standardized, but giving
+# a description of the errno is useful.
+
+LC_ALL=C
+export LC_ALL
+r=0
+
+t() {
+ exec 3>&1
+ errmsg=`cd "$1" 2>&1 >&3 3>&-`
+ exec 3>&-
+ case $errmsg in
+ *[Nn]ot\ a\ directory*)
+ ;;
+ *)
+ printf "Wrong error message for %s: %s\n" "$1" "$errmsg"
+ r=3
+ ;;
+ esac
+}
+
+t /dev/tty
+t /dev/tty/x
+exit $r
OpenPOWER on IntegriCloud