>From c38fabab3117ba8bac792012fd99cf368e076cd7 Mon Sep 17 00:00:00 2001 From: Ken Irving Date: Sun, 23 Nov 2014 21:58:05 -0900 Subject: [PATCH] stat: added %p format for one-letter types --- doc/coreutils.texi | 1 + src/stat.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 9c731b5..64c9ee8 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -11928,6 +11928,7 @@ The valid @var{format} directives for files with @option{--format} and @item %n - File name @item %N - Quoted file name with dereference if symbolic link @item %o - Optimal I/O transfer size hint +@item %p - File type as one-letter code (see find(1) -type) @item %s - Total size, in bytes @item %t - Major device type in hex (see below) @item %T - Minor device type in hex (see below) diff --git a/src/stat.c b/src/stat.c index 987f579..e4f796a 100644 --- a/src/stat.c +++ b/src/stat.c @@ -1024,6 +1024,24 @@ print_stat (char *pformat, size_t prefix_len, unsigned int m, case 'F': out_string (pformat, prefix_len, file_type (statbuf)); break; + case 'p': + if (S_ISREG (statbuf->st_mode)) + out_string (pformat, prefix_len,"f"); + else if (S_ISDIR (statbuf->st_mode)) + out_string (pformat, prefix_len,"d"); + else if (S_ISLNK (statbuf->st_mode)) + out_string (pformat, prefix_len,"l"); + else if (S_ISFIFO (statbuf->st_mode)) + out_string (pformat, prefix_len,"p"); + else if (S_ISCHR (statbuf->st_mode)) + out_string (pformat, prefix_len,"c"); + else if (S_ISBLK (statbuf->st_mode)) + out_string (pformat, prefix_len,"b"); + else if (S_ISSOCK (statbuf->st_mode)) + out_string (pformat, prefix_len,"s"); + else + out_string (pformat, prefix_len,"?"); + break; case 'h': out_uint (pformat, prefix_len, statbuf->st_nlink); break; @@ -1458,6 +1476,7 @@ The valid format sequences for files (without --file-system):\n\ %D device number in hex\n\ %f raw mode in hex\n\ %F file type\n\ + %p one-letter file type\n\ %g group ID of owner\n\ %G group name of owner\n\ "), stdout); -- 1.9.1