Source-Changes-HG archive

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

[src/netbsd-2-0]: src/usr.bin/stat Pull up revision 1.18 (requested by atatat...



details:   https://anonhg.NetBSD.org/src/rev/4bcd30588660
branches:  netbsd-2-0
changeset: 561190:4bcd30588660
user:      tron <tron%NetBSD.org@localhost>
date:      Sun May 30 07:13:26 2004 +0000

description:
Pull up revision 1.18 (requested by atatat in ticket #412):
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 4e789af92118 -r 4bcd30588660 usr.bin/stat/stat.c
--- a/usr.bin/stat/stat.c       Sun May 30 07:12:11 2004 +0000
+++ b/usr.bin/stat/stat.c       Sun May 30 07:13:26 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.17.2.1 2004/05/30 07:13:26 tron 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.17.2.1 2004/05/30 07:13:26 tron 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