diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-21 13:23:14 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-21 13:23:14 +0000 |
commit | bf66fbc8e2380717c1fab860cfc60c78582839dd (patch) | |
tree | 3ab3dd4df901851ff7f4345708592118766ba4aa /coreutils | |
parent | 6910741067913d131d931b1e6424d3b8ed43e64f (diff) | |
download | busybox-bf66fbc8e2380717c1fab860cfc60c78582839dd.tar.gz |
introduce LONE_CHAR (optimized strcmp with one-char string)
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/Kbuild | 3 | ||||
-rw-r--r-- | coreutils/cat.c | 22 | ||||
-rw-r--r-- | coreutils/diff.c | 2 | ||||
-rw-r--r-- | coreutils/echo.c | 4 | ||||
-rw-r--r-- | coreutils/expr.c | 2 | ||||
-rw-r--r-- | coreutils/test.c | 10 |
6 files changed, 26 insertions, 17 deletions
diff --git a/coreutils/Kbuild b/coreutils/Kbuild index cfb508d81..55f19b4ca 100644 --- a/coreutils/Kbuild +++ b/coreutils/Kbuild @@ -10,6 +10,7 @@ lib-y:= lib-$(CONFIG_BASENAME) += basename.o lib-$(CONFIG_CAL) += cal.o lib-$(CONFIG_CAT) += cat.o +lib-$(CONFIG_LESS) += cat.o # less uses it if stdout isn't a tty lib-$(CONFIG_CATV) += catv.o lib-$(CONFIG_CHGRP) += chgrp.o chown.o lib-$(CONFIG_CHMOD) += chmod.o @@ -28,6 +29,7 @@ lib-$(CONFIG_DIRNAME) += dirname.o lib-$(CONFIG_DOS2UNIX) += dos2unix.o lib-$(CONFIG_DU) += du.o lib-$(CONFIG_ECHO) += echo.o +lib-$(CONFIG_ASH) += echo.o # used by ash lib-$(CONFIG_ENV) += env.o lib-$(CONFIG_EXPR) += expr.o lib-$(CONFIG_FALSE) += false.o @@ -65,6 +67,7 @@ lib-$(CONFIG_SYNC) += sync.o lib-$(CONFIG_TAIL) += tail.o lib-$(CONFIG_TEE) += tee.o lib-$(CONFIG_TEST) += test.o +lib-$(CONFIG_ASH) += test.o # used by ash lib-$(CONFIG_TOUCH) += touch.o lib-$(CONFIG_TR) += tr.o lib-$(CONFIG_TRUE) += true.o diff --git a/coreutils/cat.c b/coreutils/cat.c index a95980552..db4d33dc5 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c @@ -11,20 +11,12 @@ /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ #include "busybox.h" -#include <unistd.h> -int cat_main(int argc, char **argv) +int bb_cat(char **argv) { FILE *f; int retval = EXIT_SUCCESS; - getopt32(argc, argv, "u"); - - argv += optind; - if (!*argv) { - *--argv = "-"; - } - do { f = fopen_or_warn_stdin(*argv); if (f) { @@ -39,3 +31,15 @@ int cat_main(int argc, char **argv) return retval; } + +int cat_main(int argc, char **argv) +{ + getopt32(argc, argv, "u"); + + argv += optind; + if (!*argv) { + *--argv = "-"; + } + + return bb_cat(argv); +} diff --git a/coreutils/diff.c b/coreutils/diff.c index 887679a0a..a49d5195a 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c @@ -1079,7 +1079,7 @@ static char **get_dir(char *path) dp = warn_opendir(path); while ((ep = readdir(dp))) { - if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, "."))) + if (!strcmp(ep->d_name, "..") || LONE_CHAR(ep->d_name, '.')) continue; add_to_dirlist(ep->d_name, NULL, NULL, 0); } diff --git a/coreutils/echo.c b/coreutils/echo.c index 99063ae52..0c8eac3bc 100644 --- a/coreutils/echo.c +++ b/coreutils/echo.c @@ -29,7 +29,7 @@ #include <stdlib.h> #include "busybox.h" -int bb_echo(int ATTRIBUTE_UNUSED argc, char **argv) +int bb_echo(char **argv) { #ifndef CONFIG_FEATURE_FANCY_ECHO #define eflag '\\' @@ -114,7 +114,7 @@ just_echo: int echo_main(int argc, char** argv) { - (void)bb_echo(argc, argv); + (void)bb_echo(argv); fflush_stdout_and_exit(EXIT_SUCCESS); } diff --git a/coreutils/expr.c b/coreutils/expr.c index 191473446..51e553dc6 100644 --- a/coreutils/expr.c +++ b/coreutils/expr.c @@ -136,7 +136,7 @@ static int null(VALUE * v) if (v->type == integer) return v->u.i == 0; else /* string: */ - return v->u.s[0] == '\0' || strcmp(v->u.s, "0") == 0; + return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0'); } /* Coerce V to a string value (can't fail). */ diff --git a/coreutils/test.c b/coreutils/test.c index ebb4f9086..d3d760467 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -175,14 +175,16 @@ int bb_test(int argc, char **argv) { int res; - if (strcmp(argv[0], "[") == 0) { - if (strcmp(argv[--argc], "]")) { + if (LONE_CHAR(argv[0], '[')) { + --argc; + if (NOT_LONE_CHAR(argv[argc], ']')) { bb_error_msg("missing ]"); return 2; } argv[argc] = NULL; } else if (strcmp(argv[0], "[[") == 0) { - if (strcmp(argv[--argc], "]]")) { + --argc; + if (strcmp(argv[argc], "]]")) { bb_error_msg("missing ]]"); return 2; } @@ -578,6 +580,6 @@ static int is_a_group_member(gid_t gid) int test_main(int argc, char **argv) { - exit(bb_test(argc, argv)); + return bb_test(argc, argv); } |