From 5a26a86cec424d728d43523988ca70aa56ee76c9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 2 Jun 2013 00:24:24 -0500 Subject: Stat cleanup. lib: rename format_mode() to mode_to_string() (echoing string_to_mode), make it take a normal char * argument. stat: collapse big switch/case statements that only have one line each into if/else staircase (much fewer lines of code). Remove return type (other stat implementations print ? for unknown escapes, so do that here). Inline do_stat() and do_statfs(). Set default string in normal local variable "format". Remove unnecessary struct d. Restructure stat logic to "if (flagf && !statfs()) else if (!flagf && !stat()) else perror_msg();" Teach %N to add -> symlink. Judicious use of putchar() instead of xputc to let FILE * do its job collating output. --- lib/lib.c | 10 +++++----- lib/lib.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/lib.c b/lib/lib.c index 7b0cf1a1..af820e22 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1205,13 +1205,13 @@ barf: error_exit("bad mode '%s'", modestr); } -// Format a mode for ls and stat -void format_mode(char (*buf)[11], mode_t mode) +// Format access mode into a drwxrwxrwx string +void mode_to_string(mode_t mode, char *buf) { char c, d; int i, bit; - (*buf)[10]=0; + buf[10]=0; for (i=0; i<9; i++) { bit = mode & (1<