From owner-svn-src-all@FreeBSD.ORG Sun Dec 5 09:33:04 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 70C50106566C; Sun, 5 Dec 2010 09:33:04 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5F3058FC0A; Sun, 5 Dec 2010 09:33:04 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oB59X4Zw081656; Sun, 5 Dec 2010 09:33:04 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oB59X4xq081654; Sun, 5 Dec 2010 09:33:04 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201012050933.oB59X4xq081654@svn.freebsd.org> From: Doug Barton Date: Sun, 5 Dec 2010 09:33:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216196 - head/usr.bin/stat X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Dec 2010 09:33:04 -0000 Author: dougb Date: Sun Dec 5 09:33:04 2010 New Revision: 216196 URL: http://svn.freebsd.org/changeset/base/216196 Log: 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 Modified: head/usr.bin/stat/stat.c Modified: head/usr.bin/stat/stat.c ============================================================================== --- head/usr.bin/stat/stat.c Sun Dec 5 09:00:32 2010 (r216195) +++ head/usr.bin/stat/stat.c Sun Dec 5 09:33:04 2010 (r216196) @@ -30,7 +30,7 @@ #include #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 #include +#include #include #include #include @@ -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); }