[hackers] [ubase] stat: implement -t (terse mode) || Hiltjo Posthuma
commit bbf3b5ac85988abb5899c952107f3156101d4a69
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri Apr 4 19:00:47 2014 +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_AT_codemadness.org>
diff --git a/stat.c b/stat.c
index a4e4a67..8bbb504 100644
--- a/stat.c
+++ b/stat.c
_AT_@ -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...]
", argv0);
+ eprintf("usage: %s [-L] [-t] [file...]
", argv0);
}
int
_AT_@ -33,6 +34,9 @@ main(int argc, char *argv[])
fn = stat;
fnname = "stat";
break;
+ case 't':
+ showstat = show_stat_terse;
+ break;
default:
usage();
} ARGEND;
_AT_@ -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
", (unsigned long)st->st_blksize);
+}
+
+static void
show_stat(const char *file, struct stat *st)
{
char buf[100];
Received on Fri Apr 04 2014 - 21:09:21 CEST
This archive was generated by hypermail 2.3.0
: Fri Apr 04 2014 - 21:12:23 CEST