summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/df.c7
-rw-r--r--coreutils/ls.c63
-rw-r--r--coreutils/test.c13
3 files changed, 56 insertions, 27 deletions
diff --git a/coreutils/df.c b/coreutils/df.c
index dfd6e0b..e9a865c 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -44,7 +44,6 @@ int df_main(int argc, char **argv)
FILE *mount_table;
struct mntent *mount_entry;
struct statfs s;
- static const char ignored_mounts[] ALIGN1 = "rootfs\0";
enum {
OPT_KILO = (1 << 0),
@@ -120,7 +119,7 @@ int df_main(int argc, char **argv)
mount_point = *argv++;
if (!mount_point)
break;
- mount_entry = find_mount_point(mount_point, bb_path_mtab_file);
+ mount_entry = find_mount_point(mount_point);
if (!mount_entry) {
bb_error_msg("%s: can't find mount point", mount_point);
set_error:
@@ -154,8 +153,8 @@ int df_main(int argc, char **argv)
) / (blocks_used + s.f_bavail);
}
- /* GNU coreutils 6.10 skip certain mounts, try to be compatible. */
- if (index_in_strings(device, ignored_mounts) != -1)
+ /* GNU coreutils 6.10 skips certain mounts, try to be compatible. */
+ if (strcmp(device, "rootfs") == 0)
continue;
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 61baa9a..38957e9 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -144,8 +144,7 @@ static const char ls_options[] ALIGN1 =
USE_FEATURE_LS_FOLLOWLINKS("L") /* 1, 24 */
USE_FEATURE_LS_RECURSIVE("R") /* 1, 25 */
USE_FEATURE_HUMAN_READABLE("h") /* 1, 26 */
- USE_SELINUX("K") /* 1, 27 */
- USE_SELINUX("Z") /* 1, 28 */
+ USE_SELINUX("KZ") /* 2, 28 */
USE_FEATURE_AUTOWIDTH("T:w:") /* 2, 30 */
;
enum {
@@ -162,6 +161,16 @@ enum {
OPT_Q = (1 << 10),
//OPT_A = (1 << 11),
//OPT_k = (1 << 12),
+ OPTBIT_color = 13
+ + 4 * ENABLE_FEATURE_LS_TIMESTAMPS
+ + 4 * ENABLE_FEATURE_LS_SORTFILES
+ + 2 * ENABLE_FEATURE_LS_FILETYPES
+ + 1 * ENABLE_FEATURE_LS_FOLLOWLINKS
+ + 1 * ENABLE_FEATURE_LS_RECURSIVE
+ + 1 * ENABLE_FEATURE_HUMAN_READABLE
+ + 2 * ENABLE_SELINUX
+ + 2 * ENABLE_FEATURE_AUTOWIDTH,
+ OPT_color = 1 << OPTBIT_color,
};
enum {
@@ -889,16 +898,6 @@ static int list_single(const struct dnode *dn)
}
-/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
-#if ENABLE_FEATURE_LS_COLOR
-/* long option entry used only for --color, which has no short option
- * equivalent */
-static const char ls_color_opt[] ALIGN1 =
- "color\0" Optional_argument "\xff" /* no short equivalent */
- ;
-#endif
-
-
int ls_main(int argc UNUSED_PARAM, char **argv)
{
struct dnode **dnd;
@@ -911,8 +910,25 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
int dnfiles;
int dndirs;
int i;
+#if ENABLE_FEATURE_LS_COLOR
+ /* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
+ /* coreutils 6.10:
+ * # ls --color=BOGUS
+ * ls: invalid argument 'BOGUS' for '--color'
+ * Valid arguments are:
+ * 'always', 'yes', 'force'
+ * 'never', 'no', 'none'
+ * 'auto', 'tty', 'if-tty'
+ * (and substrings: "--color=alwa" work too)
+ */
+ static const char ls_longopts[] ALIGN1 =
+ "color\0" Optional_argument "\xff"; /* no short equivalent */
+ static const char color_str[] ALIGN1 =
+ "always\0""yes\0""force\0"
+ "auto\0""tty\0""if-tty\0";
/* need to initialize since --color has _an optional_ argument */
- USE_FEATURE_LS_COLOR(const char *color_opt = "always";)
+ const char *color_opt = color_str; /* "always" */
+#endif
INIT_G();
@@ -927,7 +943,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
#endif
/* process options */
- USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;)
+ USE_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
#if ENABLE_FEATURE_AUTOWIDTH
opt_complementary = "T+:w+"; /* -T N, -w N */
opt = getopt32(argv, ls_options, &tabstops, &terminal_width
@@ -966,13 +982,20 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
if (!p || (p[0] && strcmp(p, "none") != 0))
show_color = 1;
}
- if (opt & (1 << i)) { /* next flag after short options */
- if (strcmp("always", color_opt) == 0)
- show_color = 1;
- else if (strcmp("never", color_opt) == 0)
+ if (opt & OPT_color) {
+ if (color_opt[0] == 'n')
show_color = 0;
- else if (strcmp("auto", color_opt) == 0 && isatty(STDOUT_FILENO))
- show_color = 1;
+ else switch (index_in_substrings(color_str, color_opt)) {
+ case 3:
+ case 4:
+ case 5:
+ if (isatty(STDOUT_FILENO)) {
+ case 0:
+ case 1:
+ case 2:
+ show_color = 1;
+ }
+ }
}
#endif
diff --git a/coreutils/test.c b/coreutils/test.c
index ae40192..ab7b416 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -571,7 +571,14 @@ static number_t nexpr(enum token n)
nest_msg(">nexpr(%s)\n", TOKSTR[n]);
if (n == UNOT) {
- res = !nexpr(check_operator(*++args));
+ n = check_operator(*++args);
+ if (n == EOI) {
+ /* special case: [ ! ], [ a -a ! ] are valid */
+ /* IOW, "! ARG" may miss ARG */
+ unnest_msg("<nexpr:1 (!EOI)\n");
+ return 1;
+ }
+ res = !nexpr(n);
unnest_msg("<nexpr:%lld\n", res);
return res;
}
@@ -742,7 +749,7 @@ int test_main(int argc, char **argv)
check_operator(argv[1]);
if (last_operator->op_type == BINOP) {
/* "test [!] arg1 <binary_op> arg2" */
- args = &argv[0];
+ args = argv;
res = (binop() == 0);
goto ret;
}
@@ -755,7 +762,7 @@ int test_main(int argc, char **argv)
argv--;
}
#endif
- args = &argv[0];
+ args = argv;
res = !oexpr(check_operator(*args));
if (*args != NULL && *++args != NULL) {