ls: fix bits for -T, -w and --color; make -n imply -l; fix comments
No binary (build failed)
—
(log yok)
| @@ -159,7 +159,7 @@ STYLE_MASK = STYLE_SINGLE, | |
| /* which of the three times will be used */ | |
| TIME_CHANGE = (1 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, | |
| - | TIME_ACCESS = (1 << 22) * ENABLE_FEATURE_LS_TIMESTAMPS, |
| + | TIME_ACCESS = (2 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, |
| TIME_MASK = (3 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, | |
| /* how will the files be sorted (CONFIG_FEATURE_LS_SORTFILES) */ | |
| @@ -189,10 +189,9 @@ LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \ | |
| /* Not fully compatible - we show not only '/' but other chars too */ | |
| /* -SXvhTw GNU options, busybox optionally supports */ | |
| /* -T TABWIDTH is ignored (we don't use tabs on output) */ | |
| - | /* -K SELinux mandated options, busybox optionally supports */ |
| + | /* -KZ SELinux mandated options, busybox optionally supports */ |
| + | /* (coreutils 8.4 has no -K, remove it?) */ |
| /* -e I think we made this one up (looks similar to GNU --full-time) */ | |
| - | /* Std opts we do not support: */ |
| - | /* -H Follow the links on command line only */ |
| static const char ls_options[] ALIGN1 = | |
| "Cadil1gnsxQAk" /* 13 opts, total 13 */ | |
| IF_FEATURE_LS_TIMESTAMPS("cetu") /* 4, 17 */ | |
| @@ -235,7 +234,7 @@ enum { | |
| OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX, | |
| OPTBIT_H, /* 27 */ | |
| OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS, | |
| - | OPTBIT_T = OPTBIT_h + 2 * ENABLE_FEATURE_HUMAN_READABLE, |
| + | OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE, |
| OPTBIT_w, /* 30 */ | |
| OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH, | |
| @@ -269,12 +268,12 @@ static const uint32_t opt_flags[] = { | |
| LIST_LONG | STYLE_LONG, /* l */ | |
| STYLE_SINGLE, /* 1 */ | |
| 0, /* g (don't show owner) - handled via OPT_g */ | |
| - | LIST_ID_NUMERIC, /* n */ |
| + | LIST_ID_NUMERIC | LIST_LONG | STYLE_LONG, /* n (assumes l) */ |
| LIST_BLOCKS, /* s */ | |
| DISP_ROWS | STYLE_COLUMNAR, /* x */ | |
| 0, /* Q (quote filename) - handled via OPT_Q */ | |
| DISP_HIDDEN, /* A */ | |
| - | ENABLE_SELINUX * LIST_CONTEXT, /* k (ignored if !SELINUX) */ |
| + | ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */ |
| #if ENABLE_FEATURE_LS_TIMESTAMPS | |
| TIME_CHANGE | (ENABLE_FEATURE_LS_SORTFILES * SORT_CTIME), /* c */ | |
| LIST_FULLTIME, /* e */ | |
| @@ -295,8 +294,8 @@ static const uint32_t opt_flags[] = { | |
| DISP_RECURSIVE, /* R */ | |
| #endif | |
| #if ENABLE_SELINUX | |
| - | LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */ |
| - | LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT, /* Z */ |
| + | LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME|STYLE_SINGLE, /* K */ |
| + | LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT|STYLE_SINGLE, /* Z */ |
| #endif | |
| (1U << 31) | |
| /* options after Z are not processed through opt_flags */ | |
| @@ -688,8 +687,16 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |
| column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode)); | |
| if (all_fmt & LIST_NLINKS) | |
| column += printf("%4lu ", (long) dn->dstat.st_nlink); | |
| + | if (all_fmt & LIST_ID_NUMERIC) { |
| + | if (option_mask32 & OPT_g) |
| + | column += printf("%-8u ", (int) dn->dstat.st_gid); |
| + | else |
| + | column += printf("%-8u %-8u ", |
| + | (int) dn->dstat.st_uid, |
| + | (int) dn->dstat.st_gid); |
| + | } |
| #if ENABLE_FEATURE_LS_USERNAME | |
| - | if (all_fmt & LIST_ID_NAME) { |
| + | else if (all_fmt & LIST_ID_NAME) { |
| if (option_mask32 & OPT_g) { | |
| column += printf("%-8.8s ", | |
| get_cached_groupname(dn->dstat.st_gid)); | |
| @@ -700,14 +707,6 @@ static NOINLINE unsigned list_single(const struct dnode *dn) | |
| } | |
| } | |
| #endif | |
| - | if (all_fmt & LIST_ID_NUMERIC) { |
| - | if (option_mask32 & OPT_g) |
| - | column += printf("%-8u ", (int) dn->dstat.st_gid); |
| - | else |
| - | column += printf("%-8u %-8u ", |
| - | (int) dn->dstat.st_uid, |
| - | (int) dn->dstat.st_gid); |
| - | } |
| if (all_fmt & LIST_SIZE) { | |
| if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { | |
| column += printf("%4u, %3u ", | |
| @@ -1040,7 +1039,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |
| init_unicode(); | |
| - | all_fmt = ENABLE_FEATURE_LS_SORTFILES * SORT_NAME; |
| + | if (ENABLE_FEATURE_LS_SORTFILES) |
| + | all_fmt = SORT_NAME; |
| #if ENABLE_FEATURE_AUTOWIDTH | |
| /* obtain the terminal width */ | |
| @@ -1081,8 +1081,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |
| if (flags & TIME_MASK) | |
| all_fmt &= ~TIME_MASK; | |
| - | if (flags & LIST_CONTEXT) |
| - | all_fmt |= STYLE_SINGLE; |
| all_fmt |= flags; | |
| } | |
| } | |
| @@ -1121,11 +1119,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |
| if (all_fmt & TIME_ACCESS) | |
| all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME; | |
| } | |
| - | if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* only for long list */ |
| + | if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* not -l? */ |
| all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME|LIST_FULLTIME); | |
| - | if (ENABLE_FEATURE_LS_USERNAME) |
| - | if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC)) |
| - | all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */ |
| /* choose a display format if one was not already specified by an option */ | |
| if (!(all_fmt & STYLE_MASK)) | |