commit bbf3b5ac85988abb5899c952107f3156101d4a69
parent 139522b45e499b58b32e100777af701e75c895f2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 4 Apr 2014 19:00:47 +0200
stat: implement -t (terse mode)
mostly compatible with coreutils and busybox. file mode is intentionally not compatible though.
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
Diffstat:
M | stat.c | | | 20 | +++++++++++++++++++- |
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git 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;
@@ -57,6 +61,20 @@ main(int argc, char *argv[])
}
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)
{
char buf[100];