diff options
| author | Rob Landley <rob@landley.net> | 2013-06-02 00:24:24 -0500 | 
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2013-06-02 00:24:24 -0500 | 
| commit | 5a26a86cec424d728d43523988ca70aa56ee76c9 (patch) | |
| tree | 1fe0b2b665800d0cb25d3ab0a78f31cbe85e2acd /lib | |
| parent | 085f23692575e93142df2347cfe76dd173f23e16 (diff) | |
| download | toybox-5a26a86cec424d728d43523988ca70aa56ee76c9.tar.gz | |
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.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/lib.c | 10 | ||||
| -rw-r--r-- | lib/lib.h | 2 | 
2 files changed, 6 insertions, 6 deletions
| @@ -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<<i);      c = i%3; @@ -1219,7 +1219,7 @@ void format_mode(char (*buf)[11], mode_t mode)        c = "tss"[d];        if (!bit) c &= ~0x20;      } else c = bit ? "xwr"[c] : '-'; -    (*buf)[9-i] = c; +    buf[9-i] = c;    }    if (S_ISDIR(mode)) c = 'd'; @@ -1229,7 +1229,7 @@ void format_mode(char (*buf)[11], mode_t mode)    else if (S_ISFIFO(mode)) c = 'p';    else if (S_ISSOCK(mode)) c = 's';    else c = '-'; -  **buf = c; +  *buf = c;  }  char* make_human_readable(unsigned long long size, unsigned long unit) @@ -180,7 +180,7 @@ int sig_to_num(char *pidstr);  char *num_to_sig(int sig);  mode_t string_to_mode(char *mode_str, mode_t base); -void format_mode(char (*buf)[11], mode_t mode); +void mode_to_string(mode_t mode, char *buf);  // password helper functions  int read_password(char * buff, int buflen, char* mesg); | 
