From owner-svn-src-stable@FreeBSD.ORG Tue May 4 21:56:16 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 671BD1065672; Tue, 4 May 2010 21:56:16 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 566558FC08; Tue, 4 May 2010 21:56:16 +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 o44LuGc4049832; Tue, 4 May 2010 21:56:16 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o44LuGq5049829; Tue, 4 May 2010 21:56:16 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201005042156.o44LuGq5049829@svn.freebsd.org> From: Jilles Tjoelker Date: Tue, 4 May 2010 21:56:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207636 - stable/7/usr.bin/stat X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 May 2010 21:56:16 -0000 Author: jilles Date: Tue May 4 21:56:16 2010 New Revision: 207636 URL: http://svn.freebsd.org/changeset/base/207636 Log: MFC r207153: stat: Allow -f %Sf to display the file flags symbolically. PR: 124349 Modified: stable/7/usr.bin/stat/stat.1 stable/7/usr.bin/stat/stat.c Directory Properties: stable/7/usr.bin/stat/ (props changed) Modified: stable/7/usr.bin/stat/stat.1 ============================================================================== --- stable/7/usr.bin/stat/stat.1 Tue May 4 21:23:59 2010 (r207635) +++ stable/7/usr.bin/stat/stat.1 Tue May 4 21:56:16 2010 (r207636) @@ -36,7 +36,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 27, 2007 +.Dd April 24, 2010 .Dt STAT 1 .Os .Sh NAME @@ -239,6 +239,11 @@ Display date in format. .It Cm dr Display actual device name. +.It Cm f +Display the flags of +.Ar file +as in +.Nm ls Fl lTdo . .It Cm gu Display group or user name. .It Cm p Modified: stable/7/usr.bin/stat/stat.c ============================================================================== --- stable/7/usr.bin/stat/stat.c Tue May 4 21:23:59 2010 (r207635) +++ stable/7/usr.bin/stat/stat.c Tue May 4 21:56:16 2010 (r207636) @@ -187,6 +187,9 @@ int format1(const struct stat *, /* stat char *, size_t, /* a place to put the output */ int, int, int, int, /* the parsed format */ int, int); +#if HAVE_STRUCT_STAT_ST_FLAGS +char *xfflagstostr(unsigned long); +#endif char *timefmt; int linkfail; @@ -329,6 +332,25 @@ main(int argc, char *argv[]) return (am_readlink ? linkfail : errs); } +#if HAVE_STRUCT_STAT_ST_FLAGS +/* + * fflagstostr() wrapper that leaks only once + */ +char * +xfflagstostr(unsigned long fflags) +{ + static char *str = NULL; + + if (str != NULL) + free(str); + + str = fflagstostr(fflags); + if (str == NULL) + err(1, "fflagstostr"); + return (str); +} +#endif /* HAVE_STRUCT_STAT_ST_FLAGS */ + void usage(const char *synopsis) { @@ -721,8 +743,11 @@ format1(const struct stat *st, case SHOW_st_flags: small = (sizeof(st->st_flags) == 4); data = st->st_flags; - sdata = NULL; - formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX; + sdata = xfflagstostr(st->st_flags); + if (*sdata == '\0') + sdata = "-"; + formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX | + FMTF_STRING; if (ofmt == 0) ofmt = FMTF_UNSIGNED; break;