svn commit: r247063 - in stable/8: bin/sh tools/regression/bin/sh/builtins
Jilles Tjoelker
jilles at FreeBSD.org
Wed Feb 20 23:26:16 UTC 2013
Author: jilles
Date: Wed Feb 20 23:26:14 2013
New Revision: 247063
URL: http://svnweb.freebsd.org/changeset/base/247063
Log:
MFC r222292,r230095: Show errno messages in cd.
Added:
stable/8/tools/regression/bin/sh/builtins/cd8.0
- copied unchanged from r230095, head/tools/regression/bin/sh/builtins/cd8.0
Modified:
stable/8/bin/sh/cd.c
Directory Properties:
stable/8/bin/sh/ (props changed)
stable/8/tools/regression/bin/sh/ (props changed)
Modified: stable/8/bin/sh/cd.c
==============================================================================
--- stable/8/bin/sh/cd.c Wed Feb 20 23:15:40 2013 (r247062)
+++ stable/8/bin/sh/cd.c Wed Feb 20 23:26:14 2013 (r247063)
@@ -84,6 +84,7 @@ cdcmd(int argc, char **argv)
char *p;
struct stat statb;
int ch, phys, print = 0;
+ int errno1 = ENOENT;
optreset = 1; optind = 1; opterr = 0; /* initialize getopt */
phys = Pflag;
@@ -120,7 +121,12 @@ cdcmd(int argc, char **argv)
if (*dest == '/' || (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
@@ -132,9 +138,11 @@ cdcmd(int argc, char **argv)
}
if (docd(p, print, phys) >= 0)
return 0;
+ if (errno != ENOENT)
+ errno1 = errno;
}
}
- error("can't cd to %s", dest);
+ error("%s: %s", dest, strerror(errno1));
/*NOTREACHED*/
return 0;
}
Copied: stable/8/tools/regression/bin/sh/builtins/cd8.0 (from r230095, head/tools/regression/bin/sh/builtins/cd8.0)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ stable/8/tools/regression/bin/sh/builtins/cd8.0 Wed Feb 20 23:26:14 2013 (r247063, copy of r230095, head/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
More information about the svn-src-all
mailing list