diff options
author | Denys Vlasenko | 2011-05-13 17:27:15 +0200 |
---|---|---|
committer | Denys Vlasenko | 2011-05-13 17:27:15 +0200 |
commit | d27ac299eb34fc2be3038d029e8cd581138d0a06 (patch) | |
tree | 39d6e1e43630e5f084ce8170144beb567c53b6fa | |
parent | 3a240212d9133d7d8a4462e0410380c4eaf91c90 (diff) | |
download | busybox-d27ac299eb34fc2be3038d029e8cd581138d0a06.zip busybox-d27ac299eb34fc2be3038d029e8cd581138d0a06.tar.gz |
ls: code shrink
function old new delta
list_single 990 961 -29
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/ls.c | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index 145e778..0914d75 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -659,23 +659,19 @@ static unsigned print_name(const char *name) static NOINLINE unsigned list_single(const struct dnode *dn) { unsigned column = 0; - char *lpath = lpath; /* for compiler */ + char *lpath; #if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR struct stat info; char append; #endif - /* Never happens: - if (dn->fullname == NULL) - return 0; - */ - #if ENABLE_FEATURE_LS_FILETYPES append = append_char(dn->dstat.st_mode); #endif /* Do readlink early, so that if it fails, error message * does not appear *inside* the "ls -l" line */ + lpath = NULL; if (all_fmt & LIST_SYMLINK) if (S_ISLNK(dn->dstat.st_mode)) lpath = xmalloc_readlink_or_warn(dn->fullname); @@ -763,7 +759,7 @@ static NOINLINE unsigned list_single(const struct dnode *dn) #if ENABLE_FEATURE_LS_COLOR if (show_color) { - info.st_mode = 0; /* for fgcolor() */ + info.st_mode = 0; lstat(dn->fullname, &info); printf("\033[%u;%um", bold(info.st_mode), fgcolor(info.st_mode)); @@ -774,29 +770,26 @@ static NOINLINE unsigned list_single(const struct dnode *dn) printf("\033[0m"); } - if (all_fmt & LIST_SYMLINK) { - if (S_ISLNK(dn->dstat.st_mode) && lpath) { - printf(" -> "); + if (lpath) { + printf(" -> "); #if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR -#if ENABLE_FEATURE_LS_COLOR - info.st_mode = 0; /* for fgcolor() */ -#endif - if (stat(dn->fullname, &info) == 0) { - append = append_char(info.st_mode); - } + info.st_mode = 0; + stat(dn->fullname, &info); +# if ENABLE_FEATURE_LS_FILETYPES + append = append_char(info.st_mode); +# endif #endif #if ENABLE_FEATURE_LS_COLOR - if (show_color) { - printf("\033[%u;%um", bold(info.st_mode), - fgcolor(info.st_mode)); - } + if (show_color) { + printf("\033[%u;%um", bold(info.st_mode), + fgcolor(info.st_mode)); + } #endif - column += print_name(lpath) + 4; - if (show_color) { - printf("\033[0m"); - } - free(lpath); + column += print_name(lpath) + 4; + if (show_color) { + printf("\033[0m"); } + free(lpath); } #if ENABLE_FEATURE_LS_FILETYPES if (all_fmt & LIST_FILETYPE) { @@ -902,9 +895,7 @@ static struct dnode **list_dir(const char *, unsigned *); static void showdirs(struct dnode **dn, int first) { unsigned nfiles; - unsigned dndirs; struct dnode **subdnp; - struct dnode **dnd; for (; *dn; dn++) { if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) { @@ -925,6 +916,8 @@ static void showdirs(struct dnode **dn, int first) if (ENABLE_FEATURE_LS_RECURSIVE && (all_fmt & DISP_RECURSIVE) ) { + struct dnode **dnd; + unsigned dndirs; /* recursive - list the sub-dirs */ dnd = splitdnarray(subdnp, SPLIT_SUBDIR); dndirs = count_dirs(subdnp, SPLIT_SUBDIR); @@ -950,11 +943,6 @@ static struct dnode **list_dir(const char *path, unsigned *nfiles_p) DIR *dir; unsigned i, nfiles; - /* Never happens: - if (path == NULL) - return NULL; - */ - *nfiles_p = 0; dir = warn_opendir(path); if (dir == NULL) { @@ -1150,6 +1138,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) ) /* ... or if -H: */ || (option_mask32 & OPT_H) + /* ... or if -L, but my_stat always follows links if -L */ ); argv++; if (!cur) |