1 diff -urpN busybox-1.14.2/coreutils/ls.c busybox-1.14.2-ls/coreutils/ls.c
2 --- busybox-1.14.2/coreutils/ls.c 2009-06-22 00:40:29.000000000 +0200
3 +++ busybox-1.14.2-ls/coreutils/ls.c 2009-07-03 12:46:16.000000000 +0200
4 @@ -144,8 +144,7 @@ static const char ls_options[] ALIGN1 =
5 USE_FEATURE_LS_FOLLOWLINKS("L") /* 1, 24 */
6 USE_FEATURE_LS_RECURSIVE("R") /* 1, 25 */
7 USE_FEATURE_HUMAN_READABLE("h") /* 1, 26 */
8 - USE_SELINUX("K") /* 1, 27 */
9 - USE_SELINUX("Z") /* 1, 28 */
10 + USE_SELINUX("KZ") /* 2, 28 */
11 USE_FEATURE_AUTOWIDTH("T:w:") /* 2, 30 */
14 @@ -162,6 +161,16 @@ enum {
19 + + 4 * ENABLE_FEATURE_LS_TIMESTAMPS
20 + + 4 * ENABLE_FEATURE_LS_SORTFILES
21 + + 2 * ENABLE_FEATURE_LS_FILETYPES
22 + + 1 * ENABLE_FEATURE_LS_FOLLOWLINKS
23 + + 1 * ENABLE_FEATURE_LS_RECURSIVE
24 + + 1 * ENABLE_FEATURE_HUMAN_READABLE
25 + + 2 * ENABLE_SELINUX
26 + + 2 * ENABLE_FEATURE_AUTOWIDTH,
27 + OPT_color = 1 << OPTBIT_color,
31 @@ -889,16 +898,6 @@ static int list_single(const struct dnod
35 -/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
36 -#if ENABLE_FEATURE_LS_COLOR
37 -/* long option entry used only for --color, which has no short option
39 -static const char ls_color_opt[] ALIGN1 =
40 - "color\0" Optional_argument "\xff" /* no short equivalent */
45 int ls_main(int argc UNUSED_PARAM, char **argv)
48 @@ -911,8 +910,25 @@ int ls_main(int argc UNUSED_PARAM, char
52 +#if ENABLE_FEATURE_LS_COLOR
53 + /* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
55 + * # ls --color=BOGUS
56 + * ls: invalid argument 'BOGUS' for '--color'
57 + * Valid arguments are:
58 + * 'always', 'yes', 'force'
59 + * 'never', 'no', 'none'
60 + * 'auto', 'tty', 'if-tty'
61 + * (and substrings: "--color=alwa" work too)
63 + static const char ls_longopts[] ALIGN1 =
64 + "color\0" Optional_argument "\xff"; /* no short equivalent */
65 + static const char color_str[] ALIGN1 =
66 + "always\0""yes\0""force\0"
67 + "auto\0""tty\0""if-tty\0";
68 /* need to initialize since --color has _an optional_ argument */
69 - USE_FEATURE_LS_COLOR(const char *color_opt = "always";)
70 + const char *color_opt = color_str; /* "always" */
75 @@ -927,7 +943,7 @@ int ls_main(int argc UNUSED_PARAM, char
79 - USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;)
80 + USE_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
81 #if ENABLE_FEATURE_AUTOWIDTH
82 opt_complementary = "T+:w+"; /* -T N, -w N */
83 opt = getopt32(argv, ls_options, &tabstops, &terminal_width
84 @@ -966,13 +982,20 @@ int ls_main(int argc UNUSED_PARAM, char
85 if (!p || (p[0] && strcmp(p, "none") != 0))
88 - if (opt & (1 << i)) { /* next flag after short options */
89 - if (strcmp("always", color_opt) == 0)
91 - else if (strcmp("never", color_opt) == 0)
92 + if (opt & OPT_color) {
93 + if (color_opt[0] == 'n')
95 - else if (strcmp("auto", color_opt) == 0 && isatty(STDOUT_FILENO))
97 + else switch (index_in_substrings(color_str, color_opt)) {
101 + if (isatty(STDOUT_FILENO)) {
111 diff -urpN busybox-1.14.2/testsuite/ls/ls-1-works busybox-1.14.2-ls/testsuite/ls/ls-1-works
112 --- busybox-1.14.2/testsuite/ls/ls-1-works 2009-06-22 00:32:00.000000000 +0200
113 +++ busybox-1.14.2-ls/testsuite/ls/ls-1-works 2009-07-02 14:28:45.000000000 +0200
116 -ls -1 "$d" > logfile.gnu
117 -busybox ls -1 "$d" > logfile.bb
118 -cmp logfile.gnu logfile.bb
119 +LC_ALL=C ls -1 "$d" > logfile.gnu
120 +LC_ALL=C busybox ls -1 "$d" > logfile.bb
121 +diff -ubw logfile.gnu logfile.bb
122 diff -urpN busybox-1.14.2/testsuite/ls/ls-h-works busybox-1.14.2-ls/testsuite/ls/ls-h-works
123 --- busybox-1.14.2/testsuite/ls/ls-h-works 2009-06-22 00:32:00.000000000 +0200
124 +++ busybox-1.14.2-ls/testsuite/ls/ls-h-works 2009-07-02 14:28:45.000000000 +0200
127 -ls -h "$d" > logfile.gnu
128 -busybox ls -h "$d" > logfile.bb
129 -cmp logfile.gnu logfile.bb
130 +LC_ALL=C ls -h "$d" > logfile.gnu
131 +LC_ALL=C busybox ls -h "$d" > logfile.bb
132 +diff -ubw logfile.gnu logfile.bb
133 diff -urpN busybox-1.14.2/testsuite/ls/ls-l-works busybox-1.14.2-ls/testsuite/ls/ls-l-works
134 --- busybox-1.14.2/testsuite/ls/ls-l-works 2009-06-22 00:32:00.000000000 +0200
135 +++ busybox-1.14.2-ls/testsuite/ls/ls-l-works 2009-07-02 14:28:45.000000000 +0200
138 LC_ALL=C ls -l "$d" > logfile.gnu
139 -busybox ls -l "$d" > logfile.bb
140 -diff -w logfile.gnu logfile.bb
141 +LC_ALL=C busybox ls -l "$d" > logfile.bb
142 +diff -ubw logfile.gnu logfile.bb
143 diff -urpN busybox-1.14.2/testsuite/ls/ls-s-works busybox-1.14.2-ls/testsuite/ls/ls-s-works
144 --- busybox-1.14.2/testsuite/ls/ls-s-works 2009-06-22 00:32:00.000000000 +0200
145 +++ busybox-1.14.2-ls/testsuite/ls/ls-s-works 2009-07-02 14:28:45.000000000 +0200
148 LC_ALL=C ls -1s "$d" > logfile.gnu
149 -busybox ls -1s "$d" > logfile.bb
150 -cmp logfile.gnu logfile.bb
151 +LC_ALL=C busybox ls -1s "$d" > logfile.bb
152 +diff -ubw logfile.gnu logfile.bb