Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/stat If using stat (the -L flag) and it fails, fall ...



details:   https://anonhg.NetBSD.org/src/rev/33d3042a5595
branches:  trunk
changeset: 567023:33d3042a5595
user:      atatat <atatat%NetBSD.org@localhost>
date:      Fri May 28 04:48:31 2004 +0000

description:
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:

 usr.bin/stat/stat.c |  18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diffs (46 lines):

diff -r a5e257c7a573 -r 33d3042a5595 usr.bin/stat/stat.c
--- a/usr.bin/stat/stat.c       Fri May 28 03:55:30 2004 +0000
+++ b/usr.bin/stat/stat.c       Fri May 28 04:48:31 2004 +0000
@@ -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 @@
 
 #include <ctype.h>
 #include <err.h>
+#include <errno.h>
 #include <grp.h>
 #include <limits.h>
 #include <pwd.h>
@@ -306,8 +307,17 @@
        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);
 



Home | Main Index | Thread Index | Old Index