summaryrefslogtreecommitdiffstats
path: root/bin/sh/cd.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2012-01-13 23:32:27 +0000
committerjilles <jilles@FreeBSD.org>2012-01-13 23:32:27 +0000
commit69e6f0d41657559b7c7414462d57136cc7184f41 (patch)
tree4d216d3f8f08c09184dfe315554ff5b7157a73fb /bin/sh/cd.c
parenta97c56fa2ab8649a7f6695df50ab3c6cc735d54f (diff)
downloadFreeBSD-src-69e6f0d41657559b7c7414462d57136cc7184f41.zip
FreeBSD-src-69e6f0d41657559b7c7414462d57136cc7184f41.tar.gz
sh: Properly show "Not a directory" error in cd builtin.
The errno message display added in r222292 did not take attempting to cd to a non-directory or something that cannot be stat()ed into account. PR: bin/164070 MFC after: 10 days
Diffstat (limited to 'bin/sh/cd.c')
-rw-r--r--bin/sh/cd.c7
1 files changed, 6 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
OpenPOWER on IntegriCloud