diff options
| author | atatat <atatat@NetBSD.org> | 2004-05-28 04:48:31 +0000 |
|---|---|---|
| committer | atatat <atatat@NetBSD.org> | 2004-05-28 04:48:31 +0000 |
| commit | 90bf99f1fb35f8affad099c8df7b3b9ffaa5a317 (patch) | |
| tree | a995d2003a7230085574d1d59878a0b517d4437d /usr.bin/stat/stat.c | |
| parent | 5a942efb7be92b24c6dcb3b248b0be283cf0e82a (diff) | |
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.
Diffstat (limited to 'usr.bin/stat/stat.c')
| -rw-r--r-- | usr.bin/stat/stat.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c index 7eba7614c5c..d6e6811063a 100644 --- a/usr.bin/stat/stat.c +++ b/usr.bin/stat/stat.c @@ -1,4 +1,4 @@ -/* $NetBSD: stat.c,v 1.17 2003/10/29 04:25:46 atatat Exp $ */ +/* $NetBSD: stat.c,v 1.18 2004/05/28 04:48:31 atatat Exp $ */ /* * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -42,7 +42,7 @@ #include <sys/cdefs.h> #if !defined(lint) -__RCSID("$NetBSD: stat.c,v 1.17 2003/10/29 04:25:46 atatat Exp $"); +__RCSID("$NetBSD: stat.c,v 1.18 2004/05/28 04:48:31 atatat Exp $"); #endif #if ! HAVE_NBTOOL_CONFIG_H @@ -58,6 +58,7 @@ __RCSID("$NetBSD: stat.c,v 1.17 2003/10/29 04:25:46 atatat Exp $"); #include <ctype.h> #include <err.h> +#include <errno.h> #include <grp.h> #include <limits.h> #include <pwd.h> @@ -306,8 +307,17 @@ main(int argc, char *argv[]) do { if (argc == 0) rc = fstat(STDIN_FILENO, &st); - else if (usestat) - rc = stat(argv[0], &st); + else if (usestat) { + /* + * Try stat() and if it fails, fall back to + * lstat() just in case we're examining a + * broken symlink. + */ + if ((rc = stat(argv[0], &st)) == -1 && + errno == ENOENT && + (rc = lstat(argv[0], &st)) == -1) + errno = ENOENT; + } else rc = lstat(argv[0], &st); |
