diff options
author | jilles <jilles@FreeBSD.org> | 2010-04-24 13:53:12 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-04-24 13:53:12 +0000 |
commit | d64653ea1ca054cd1ba07612729e26d81aa57e23 (patch) | |
tree | 88d8710c85fc78f30460df1e73ae19f17f059007 /usr.bin/stat/stat.c | |
parent | e91c695f77327172ce0a6826362a20989822e97b (diff) | |
download | FreeBSD-src-d64653ea1ca054cd1ba07612729e26d81aa57e23.zip FreeBSD-src-d64653ea1ca054cd1ba07612729e26d81aa57e23.tar.gz |
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
Diffstat (limited to 'usr.bin/stat/stat.c')
-rw-r--r-- | usr.bin/stat/stat.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c index 83d389b..1ab10ea 100644 --- a/usr.bin/stat/stat.c +++ b/usr.bin/stat/stat.c @@ -182,6 +182,9 @@ int format1(const struct stat *, /* stat info */ 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; |