aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/stat
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2010-12-05 09:33:04 +0000
committerDoug Barton <dougb@FreeBSD.org>2010-12-05 09:33:04 +0000
commitccdbe8ce16caecda8d847db357a4b132336a6a09 (patch)
tree7b65d7c66b0f7d02921540145c0626c872fd643f /usr.bin/stat
parent2d5c617a52da1cba389fd569224b0529c8337b2f (diff)
Notes
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 1ab10ea4b08bd..63c242b9b9b0d 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);
}