From bbf3b5ac85988abb5899c952107f3156101d4a69 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 4 Apr 2014 19:00:47 +0200 Subject: [PATCH] stat: implement -t (terse mode) mostly compatible with coreutils and busybox. file mode is intentionally not compatible though. Signed-off-by: Hiltjo Posthuma --- stat.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/stat.c b/stat.c index a4e4a67..8bbb504 100644 --- a/stat.c +++ b/stat.c @@ -12,11 +12,12 @@ #include "util.h" static void show_stat(const char *file, struct stat *st); +static void show_stat_terse(const char *file, struct stat *st); static void usage(void) { - eprintf("usage: %s [-L] [file...]\n", argv0); + eprintf("usage: %s [-L] [-t] [file...]\n", argv0); } int @@ -33,6 +34,9 @@ main(int argc, char *argv[]) fn = stat; fnname = "stat"; break; + case 't': + showstat = show_stat_terse; + break; default: usage(); } ARGEND; @@ -56,6 +60,20 @@ main(int argc, char *argv[]) return ret; } +static void +show_stat_terse(const char *file, struct stat *st) +{ + printf("%s ", file); + printf("%lu %lu ", (unsigned long)st->st_size, + (unsigned long)st->st_blocks); + printf("%04o %u %u ", st->st_mode & 0777, st->st_uid, st->st_gid); + printf("%llx ", (unsigned long long)st->st_dev); + printf("%lu %lu ", (unsigned long)st->st_ino, (unsigned long)st->st_nlink); + printf("%d %d ", major(st->st_rdev), minor(st->st_rdev)); + printf("%ld %ld %ld ", st->st_atime, st->st_mtime, st->st_ctime); + printf("%lu\n", (unsigned long)st->st_blksize); +} + static void show_stat(const char *file, struct stat *st) {