summaryrefslogtreecommitdiffstats
path: root/usr.bin/stat
diff options
context:
space:
mode:
authordougb <dougb@FreeBSD.org>2010-12-05 09:33:04 +0000
committerdougb <dougb@FreeBSD.org>2010-12-05 09:33:04 +0000
commit4bc6f6479f031b4131c03bf9ed4c18837fda8307 (patch)
tree7b65d7c66b0f7d02921540145c0626c872fd643f /usr.bin/stat
parentf8b10ad3cb44297f92afff49601c5f48044d5e91 (diff)
downloadFreeBSD-src-4bc6f6479f031b4131c03bf9ed4c18837fda8307.zip
FreeBSD-src-4bc6f6479f031b4131c03bf9ed4c18837fda8307.tar.gz
Bring in the change from NetBSD 1.18:
"If using stat (the -L flag) and it fails, fall back to lstat(). It may be the case that we're examining a broken symlink, and anything is better than nothing." The changes in 1.14 through 1.17 were not relevant to us. Obtained from: atatat@NetBSD.org
Diffstat (limited to 'usr.bin/stat')
-rw-r--r--usr.bin/stat/stat.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c
index 1ab10ea..63c242b 100644
--- a/usr.bin/stat/stat.c
+++ b/usr.bin/stat/stat.c
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if 0
#ifndef lint
-__RCSID("$NetBSD: stat.c,v 1.13 2003/07/25 03:21:17 atatat Exp $");
+__RCSID("$NetBSD: stat.c,v 1.18 2004/05/28 04:48:31 atatat Exp $");
#endif
#endif
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <grp.h>
#include <limits.h>
#include <paths.h>
@@ -313,8 +314,17 @@ main(int argc, char *argv[])
rc = fstat(STDIN_FILENO, &st);
} else {
file = argv[0];
- if (usestat)
- rc = stat(file, &st);
+ if (usestat) {
+ /*
+ * Try stat() and if it fails, fall back to
+ * lstat() just in case we're examining a
+ * broken symlink.
+ */
+ if ((rc = stat(file, &st)) == -1 &&
+ errno == ENOENT &&
+ (rc = lstat(file, &st)) == -1)
+ errno = ENOENT;
+ }
else
rc = lstat(file, &st);
}
OpenPOWER on IntegriCloud