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>
This commit is contained in:
Hiltjo Posthuma 2014-04-04 19:00:47 +02:00 committed by sin
parent 139522b45e
commit bbf3b5ac85
1 changed files with 19 additions and 1 deletions

20
stat.c
View File

@ -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)
{