From owner-svn-src-all@FreeBSD.ORG Sun Dec 5 21:11:46 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 2C7D51065674; Sun, 5 Dec 2010 21:11:46 +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 1BA998FC1C; Sun, 5 Dec 2010 21:11:46 +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 oB5LBkKw008513; Sun, 5 Dec 2010 21:11:46 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oB5LBjqX008511; Sun, 5 Dec 2010 21:11:45 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201012052111.oB5LBjqX008511@svn.freebsd.org> From: Doug Barton Date: Sun, 5 Dec 2010 21:11:45 +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: r216203 - 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 21:11:46 -0000 Author: dougb Date: Sun Dec 5 21:11:45 2010 New Revision: 216203 URL: http://svn.freebsd.org/changeset/base/216203 Log: Bring in a new feature, adding a -f option to readlink to print the path of the target, similar to realpath(1). See the discussion at: http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=34662 This brings in the following changes: 1.24 "PR/34662: martijnb at atlas dot ipv6 dot stack dot nl: readlink doesn't grok -f, and there's no alternative (+fix) Patch applied with minor tweak (%y -> %R, as it was already taken) plus some nits from myself. Thanks!" Obtained from: elad@NetBSD.org 1.25 "Fix a segfault when doing 'stat -f %R' on the stdin file handle, instead fake the filename '(stdin)' like the %N format." Obtained from: mlelstv@NetBSD.org 1.27 "The ofmt variable is actually a bit mask (not the character that was in the format string) so that we can "or" it with the bits in the formats variable. This fixes the missing " -> " in front of the real path (when you use %SR). Also, the ?: needs another space." Obtained from: atatat@NetBSD.org I am purposely omitting the following changes: 1.23 A humanize_number(3) clone that should better be implemented by actually using humanize_number(3) 1.26 This is the removal of license clause 3 and 4, already handled by imp in r203971 Modified: head/usr.bin/stat/stat.c Modified: head/usr.bin/stat/stat.c ============================================================================== --- head/usr.bin/stat/stat.c Sun Dec 5 20:47:53 2010 (r216202) +++ head/usr.bin/stat/stat.c Sun Dec 5 21:11:45 2010 (r216203) @@ -30,7 +30,7 @@ #include #if 0 #ifndef lint -__RCSID("$NetBSD: stat.c,v 1.22 2005/04/22 03:36:48 atatat Exp $"); +__RCSID("$NetBSD: stat.c,v 1.27 2008/05/16 17:58:33 atatat Exp $"); #endif #endif @@ -153,6 +153,7 @@ __FBSDID("$FreeBSD$"); #define MIDDLE_PIECE 'M' #define LOW_PIECE 'L' +#define SHOW_realpath 'R' #define SHOW_st_dev 'd' #define SHOW_st_ino 'i' #define SHOW_st_mode 'p' @@ -218,8 +219,8 @@ main(int argc, char *argv[]) if (strcmp(getprogname(), "readlink") == 0) { am_readlink = 1; - options = "n"; - synopsis = "[-n] [file ...]"; + options = "fn"; + synopsis = "[-fn] [file ...]"; statfmt = "%Y"; fmtchar = 'f'; quiet = 1; @@ -243,6 +244,10 @@ main(int argc, char *argv[]) quiet = 1; break; case 'f': + if (am_readlink) { + statfmt = "%R"; + break; + } statfmt = optarg; /* FALLTHROUGH */ case 'l': @@ -518,6 +523,7 @@ output(const struct stat *st, const char } switch (*statfmt) { + fmtcase(what, SHOW_realpath); fmtcase(what, SHOW_st_dev); fmtcase(what, SHOW_st_ino); fmtcase(what, SHOW_st_mode); @@ -776,6 +782,26 @@ format1(const struct stat *st, ofmt = FMTF_UNSIGNED; break; #endif /* HAVE_STRUCT_STAT_ST_GEN */ + case SHOW_realpath: + small = 0; + data = 0; + if (file == NULL) { + (void)strncpy(path, "(stdin)", sizeof(path)); + sdata = path; + } else { + snprintf(path, sizeof(path), " -> "); + if (realpath(file, path + 4) == NULL) { + linkfail = 1; + l = 0; + path[0] = '\0'; + } + sdata = path + (ofmt == FMTF_STRING ? 0 : 4); + } + + formats = FMTF_STRING; + if (ofmt == 0) + ofmt = FMTF_STRING; + break; case SHOW_symlink: small = 0; data = 0;