aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-21 13:23:14 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-21 13:23:14 +0000
commitbf66fbc8e2380717c1fab860cfc60c78582839dd (patch)
tree3ab3dd4df901851ff7f4345708592118766ba4aa /coreutils
parent6910741067913d131d931b1e6424d3b8ed43e64f (diff)
downloadbusybox-w32-bf66fbc8e2380717c1fab860cfc60c78582839dd.tar.gz
busybox-w32-bf66fbc8e2380717c1fab860cfc60c78582839dd.tar.bz2
busybox-w32-bf66fbc8e2380717c1fab860cfc60c78582839dd.zip
introduce LONE_CHAR (optimized strcmp with one-char string)
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Kbuild3
-rw-r--r--coreutils/cat.c22
-rw-r--r--coreutils/diff.c2
-rw-r--r--coreutils/echo.c4
-rw-r--r--coreutils/expr.c2
-rw-r--r--coreutils/test.c10
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:=
10lib-$(CONFIG_BASENAME) += basename.o 10lib-$(CONFIG_BASENAME) += basename.o
11lib-$(CONFIG_CAL) += cal.o 11lib-$(CONFIG_CAL) += cal.o
12lib-$(CONFIG_CAT) += cat.o 12lib-$(CONFIG_CAT) += cat.o
13lib-$(CONFIG_LESS) += cat.o # less uses it if stdout isn't a tty
13lib-$(CONFIG_CATV) += catv.o 14lib-$(CONFIG_CATV) += catv.o
14lib-$(CONFIG_CHGRP) += chgrp.o chown.o 15lib-$(CONFIG_CHGRP) += chgrp.o chown.o
15lib-$(CONFIG_CHMOD) += chmod.o 16lib-$(CONFIG_CHMOD) += chmod.o
@@ -28,6 +29,7 @@ lib-$(CONFIG_DIRNAME) += dirname.o
28lib-$(CONFIG_DOS2UNIX) += dos2unix.o 29lib-$(CONFIG_DOS2UNIX) += dos2unix.o
29lib-$(CONFIG_DU) += du.o 30lib-$(CONFIG_DU) += du.o
30lib-$(CONFIG_ECHO) += echo.o 31lib-$(CONFIG_ECHO) += echo.o
32lib-$(CONFIG_ASH) += echo.o # used by ash
31lib-$(CONFIG_ENV) += env.o 33lib-$(CONFIG_ENV) += env.o
32lib-$(CONFIG_EXPR) += expr.o 34lib-$(CONFIG_EXPR) += expr.o
33lib-$(CONFIG_FALSE) += false.o 35lib-$(CONFIG_FALSE) += false.o
@@ -65,6 +67,7 @@ lib-$(CONFIG_SYNC) += sync.o
65lib-$(CONFIG_TAIL) += tail.o 67lib-$(CONFIG_TAIL) += tail.o
66lib-$(CONFIG_TEE) += tee.o 68lib-$(CONFIG_TEE) += tee.o
67lib-$(CONFIG_TEST) += test.o 69lib-$(CONFIG_TEST) += test.o
70lib-$(CONFIG_ASH) += test.o # used by ash
68lib-$(CONFIG_TOUCH) += touch.o 71lib-$(CONFIG_TOUCH) += touch.o
69lib-$(CONFIG_TR) += tr.o 72lib-$(CONFIG_TR) += tr.o
70lib-$(CONFIG_TRUE) += true.o 73lib-$(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 @@
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
12 12
13#include "busybox.h" 13#include "busybox.h"
14#include <unistd.h>
15 14
16int cat_main(int argc, char **argv) 15int bb_cat(char **argv)
17{ 16{
18 FILE *f; 17 FILE *f;
19 int retval = EXIT_SUCCESS; 18 int retval = EXIT_SUCCESS;
20 19
21 getopt32(argc, argv, "u");
22
23 argv += optind;
24 if (!*argv) {
25 *--argv = "-";
26 }
27
28 do { 20 do {
29 f = fopen_or_warn_stdin(*argv); 21 f = fopen_or_warn_stdin(*argv);
30 if (f) { 22 if (f) {
@@ -39,3 +31,15 @@ int cat_main(int argc, char **argv)
39 31
40 return retval; 32 return retval;
41} 33}
34
35int cat_main(int argc, char **argv)
36{
37 getopt32(argc, argv, "u");
38
39 argv += optind;
40 if (!*argv) {
41 *--argv = "-";
42 }
43
44 return bb_cat(argv);
45}
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)
1079 1079
1080 dp = warn_opendir(path); 1080 dp = warn_opendir(path);
1081 while ((ep = readdir(dp))) { 1081 while ((ep = readdir(dp))) {
1082 if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, "."))) 1082 if (!strcmp(ep->d_name, "..") || LONE_CHAR(ep->d_name, '.'))
1083 continue; 1083 continue;
1084 add_to_dirlist(ep->d_name, NULL, NULL, 0); 1084 add_to_dirlist(ep->d_name, NULL, NULL, 0);
1085 } 1085 }
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 @@
29#include <stdlib.h> 29#include <stdlib.h>
30#include "busybox.h" 30#include "busybox.h"
31 31
32int bb_echo(int ATTRIBUTE_UNUSED argc, char **argv) 32int bb_echo(char **argv)
33{ 33{
34#ifndef CONFIG_FEATURE_FANCY_ECHO 34#ifndef CONFIG_FEATURE_FANCY_ECHO
35#define eflag '\\' 35#define eflag '\\'
@@ -114,7 +114,7 @@ just_echo:
114 114
115int echo_main(int argc, char** argv) 115int echo_main(int argc, char** argv)
116{ 116{
117 (void)bb_echo(argc, argv); 117 (void)bb_echo(argv);
118 fflush_stdout_and_exit(EXIT_SUCCESS); 118 fflush_stdout_and_exit(EXIT_SUCCESS);
119} 119}
120 120
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)
136 if (v->type == integer) 136 if (v->type == integer)
137 return v->u.i == 0; 137 return v->u.i == 0;
138 else /* string: */ 138 else /* string: */
139 return v->u.s[0] == '\0' || strcmp(v->u.s, "0") == 0; 139 return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
140} 140}
141 141
142/* Coerce V to a string value (can't fail). */ 142/* 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)
175{ 175{
176 int res; 176 int res;
177 177
178 if (strcmp(argv[0], "[") == 0) { 178 if (LONE_CHAR(argv[0], '[')) {
179 if (strcmp(argv[--argc], "]")) { 179 --argc;
180 if (NOT_LONE_CHAR(argv[argc], ']')) {
180 bb_error_msg("missing ]"); 181 bb_error_msg("missing ]");
181 return 2; 182 return 2;
182 } 183 }
183 argv[argc] = NULL; 184 argv[argc] = NULL;
184 } else if (strcmp(argv[0], "[[") == 0) { 185 } else if (strcmp(argv[0], "[[") == 0) {
185 if (strcmp(argv[--argc], "]]")) { 186 --argc;
187 if (strcmp(argv[argc], "]]")) {
186 bb_error_msg("missing ]]"); 188 bb_error_msg("missing ]]");
187 return 2; 189 return 2;
188 } 190 }
@@ -578,6 +580,6 @@ static int is_a_group_member(gid_t gid)
578 580
579int test_main(int argc, char **argv) 581int test_main(int argc, char **argv)
580{ 582{
581 exit(bb_test(argc, argv)); 583 return bb_test(argc, argv);
582} 584}
583 585