Date: Sat, 24 Apr 2010 13:53:12 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r207153 - head/usr.bin/stat Message-ID: <201004241353.o3ODrC0L049712@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Sat Apr 24 13:53:12 2010 New Revision: 207153 URL: http://svn.freebsd.org/changeset/base/207153 Log: stat: Allow -f %Sf to display the file flags symbolically. I have changed the patch slightly to show '-' if there are no flags just like ls -ldo does. PR: 124349 Submitted by: Ighighi MFC after: 1 week Modified: head/usr.bin/stat/stat.1 head/usr.bin/stat/stat.c Modified: head/usr.bin/stat/stat.1 ============================================================================== --- head/usr.bin/stat/stat.1 Sat Apr 24 12:49:52 2010 (r207152) +++ head/usr.bin/stat/stat.1 Sat Apr 24 13:53:12 2010 (r207153) @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 27, 2007 +.Dd April 24, 2010 .Dt STAT 1 .Os .Sh NAME @@ -232,6 +232,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: head/usr.bin/stat/stat.c ============================================================================== --- head/usr.bin/stat/stat.c Sat Apr 24 12:49:52 2010 (r207152) +++ head/usr.bin/stat/stat.c Sat Apr 24 13:53:12 2010 (r207153) @@ -182,6 +182,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; @@ -333,6 +336,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) { @@ -725,8 +747,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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004241353.o3ODrC0L049712>