aboutsummaryrefslogtreecommitdiff
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
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)
-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
-rw-r--r--e2fsprogs/blkid/devname.c4
-rw-r--r--e2fsprogs/chattr.c7
-rw-r--r--e2fsprogs/ext2fs/ismounted.c2
-rw-r--r--e2fsprogs/fsck.c4
-rw-r--r--include/libbb.h6
-rw-r--r--init/init.c5
-rw-r--r--libbb/correct_password.c5
-rw-r--r--miscutils/last.c2
-rw-r--r--networking/inetd.c2
-rw-r--r--networking/libiproute/ipaddress.c2
-rw-r--r--shell/ash.c2
17 files changed, 49 insertions, 35 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
diff --git a/e2fsprogs/blkid/devname.c b/e2fsprogs/blkid/devname.c
index d69000be7..3d11734d5 100644
--- a/e2fsprogs/blkid/devname.c
+++ b/e2fsprogs/blkid/devname.c
@@ -189,7 +189,7 @@ static void lvm_probe_all(blkid_cache cache)
189 struct dirent *lv_iter; 189 struct dirent *lv_iter;
190 190
191 vg_name = vg_iter->d_name; 191 vg_name = vg_iter->d_name;
192 if (!strcmp(vg_name, ".") || !strcmp(vg_name, "..")) 192 if (LONE_CHAR(vg_name, '.') || !strcmp(vg_name, ".."))
193 continue; 193 continue;
194 vdirname = xmalloc(vg_len + strlen(vg_name) + 8); 194 vdirname = xmalloc(vg_len + strlen(vg_name) + 8);
195 sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name); 195 sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name);
@@ -203,7 +203,7 @@ static void lvm_probe_all(blkid_cache cache)
203 char *lv_name, *lvm_device; 203 char *lv_name, *lvm_device;
204 204
205 lv_name = lv_iter->d_name; 205 lv_name = lv_iter->d_name;
206 if (!strcmp(lv_name, ".") || !strcmp(lv_name, "..")) 206 if (LONE_CHAR(lv_name, '.') || !strcmp(lv_name, ".."))
207 continue; 207 continue;
208 208
209 lvm_device = xmalloc(vg_len + strlen(vg_name) + 209 lvm_device = xmalloc(vg_len + strlen(vg_name) +
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c
index 4c341627e..4848e1e1a 100644
--- a/e2fsprogs/chattr.c
+++ b/e2fsprogs/chattr.c
@@ -157,9 +157,10 @@ skip_setflags:
157static int chattr_dir_proc(const char *dir_name, struct dirent *de, 157static int chattr_dir_proc(const char *dir_name, struct dirent *de,
158 void *private EXT2FS_ATTR((unused))) 158 void *private EXT2FS_ATTR((unused)))
159{ 159{
160 /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ 160 /*if (strcmp(de->d_name, ".") || strcmp(de->d_name, "..")) {*/
161 if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ 161 if (de->d_name[0] == '.'
162 (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { 162 && (!de->d_name[1] || (de->d_name[1] == '.' && !de->d_name[2]))
163 ) {
163 char *path = concat_subpath_file(dir_name, de->d_name); 164 char *path = concat_subpath_file(dir_name, de->d_name);
164 if (path) { 165 if (path) {
165 change_attributes(path); 166 change_attributes(path);
diff --git a/e2fsprogs/ext2fs/ismounted.c b/e2fsprogs/ext2fs/ismounted.c
index cace7715c..d943f1185 100644
--- a/e2fsprogs/ext2fs/ismounted.c
+++ b/e2fsprogs/ext2fs/ismounted.c
@@ -144,7 +144,7 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file,
144 * read/write, since if the root is mounted read/only, the 144 * read/write, since if the root is mounted read/only, the
145 * contents of /etc/mtab may not be accurate. 145 * contents of /etc/mtab may not be accurate.
146 */ 146 */
147 if (!strcmp(mnt->mnt_dir, "/")) { 147 if (LONE_CHAR(mnt->mnt_dir, '/')) {
148is_root: 148is_root:
149#define TEST_FILE "/.ismount-test-file" 149#define TEST_FILE "/.ismount-test-file"
150 *mount_flags |= EXT2_MF_ISROOT; 150 *mount_flags |= EXT2_MF_ISROOT;
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index 3b01c1021..da66250f1 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -1080,7 +1080,7 @@ static int check_all(void)
1080 */ 1080 */
1081 if (!parallel_root) { 1081 if (!parallel_root) {
1082 for (fs = filesys_info; fs; fs = fs->next) { 1082 for (fs = filesys_info; fs; fs = fs->next) {
1083 if (!strcmp(fs->mountpt, "/")) 1083 if (LONE_CHAR(fs->mountpt, '/'))
1084 break; 1084 break;
1085 } 1085 }
1086 if (fs) { 1086 if (fs) {
@@ -1099,7 +1099,7 @@ static int check_all(void)
1099 */ 1099 */
1100 if (skip_root) 1100 if (skip_root)
1101 for (fs = filesys_info; fs; fs = fs->next) 1101 for (fs = filesys_info; fs; fs = fs->next)
1102 if (!strcmp(fs->mountpt, "/")) 1102 if (LONE_CHAR(fs->mountpt, '/'))
1103 fs->flags |= FLAG_DONE; 1103 fs->flags |= FLAG_DONE;
1104 1104
1105 while (not_done_yet) { 1105 while (not_done_yet) {
diff --git a/include/libbb.h b/include/libbb.h
index 7dc7abd7f..2fd54e789 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -263,6 +263,8 @@ extern char *xasprintf(const char *format, ...) __attribute__ ((format (printf,
263//int NOT_LONE_DASH(const char *s) { return s[0] != '-' || s[1]; } 263//int NOT_LONE_DASH(const char *s) { return s[0] != '-' || s[1]; }
264#define LONE_DASH(s) ((s)[0] == '-' && !(s)[1]) 264#define LONE_DASH(s) ((s)[0] == '-' && !(s)[1])
265#define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1]) 265#define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1])
266#define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
267#define NOT_LONE_CHAR(s,c) ((s)[0] != (c) || (s)[1])
266 268
267/* dmalloc will redefine these to it's own implementation. It is safe 269/* dmalloc will redefine these to it's own implementation. It is safe
268 * to have the prototypes here unconditionally. */ 270 * to have the prototypes here unconditionally. */
@@ -386,7 +388,9 @@ extern void bb_vperror_msg(const char *s, va_list p);
386extern void bb_vinfo_msg(const char *s, va_list p); 388extern void bb_vinfo_msg(const char *s, va_list p);
387 389
388 390
389extern int bb_echo(int argc, char** argv); 391/* applets which are useful from another applets */
392extern int bb_cat(char** argv);
393extern int bb_echo(char** argv);
390extern int bb_test(int argc, char** argv); 394extern int bb_test(int argc, char** argv);
391 395
392#ifndef BUILD_INDIVIDUAL 396#ifndef BUILD_INDIVIDUAL
diff --git a/init/init.c b/init/init.c
index 213a5c149..bc53feeae 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1047,8 +1047,9 @@ int init_main(int argc, char **argv)
1047 } 1047 }
1048 1048
1049 /* Check if we are supposed to be in single user mode */ 1049 /* Check if we are supposed to be in single user mode */
1050 if (argc > 1 && (!strcmp(argv[1], "single") || 1050 if (argc > 1
1051 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) { 1051 && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
1052 ) {
1052 /* Start a shell on console */ 1053 /* Start a shell on console */
1053 new_init_action(RESPAWN, bb_default_login_shell, ""); 1054 new_init_action(RESPAWN, bb_default_login_shell, "");
1054 } else { 1055 } else {
diff --git a/libbb/correct_password.c b/libbb/correct_password.c
index fd7e0b56c..d031b2109 100644
--- a/libbb/correct_password.c
+++ b/libbb/correct_password.c
@@ -40,15 +40,14 @@ int correct_password(const struct passwd *pw)
40 char *unencrypted, *encrypted, *correct; 40 char *unencrypted, *encrypted, *correct;
41 41
42#ifdef CONFIG_FEATURE_SHADOWPASSWDS 42#ifdef CONFIG_FEATURE_SHADOWPASSWDS
43 if (!strcmp(pw->pw_passwd, "x") || !strcmp(pw->pw_passwd, "*")) { 43 if (LONE_CHAR(pw->pw_passwd, 'x') || LONE_CHAR(pw->pw_passwd, '*')) {
44 struct spwd *sp = getspnam(pw->pw_name); 44 struct spwd *sp = getspnam(pw->pw_name);
45 45
46 if (!sp) 46 if (!sp)
47 bb_error_msg_and_die("no valid shadow password"); 47 bb_error_msg_and_die("no valid shadow password");
48 48
49 correct = sp->sp_pwdp; 49 correct = sp->sp_pwdp;
50 } 50 } else
51 else
52#endif 51#endif
53 correct = pw->pw_passwd; 52 correct = pw->pw_passwd;
54 53
diff --git a/miscutils/last.c b/miscutils/last.c
index 668f0c17d..fd1033bf7 100644
--- a/miscutils/last.c
+++ b/miscutils/last.c
@@ -44,7 +44,7 @@ int last_main(int argc, char **argv)
44 bb_perror_msg_and_die("short read"); 44 bb_perror_msg_and_die("short read");
45 } 45 }
46 46
47 if (strncmp(ut.ut_line, "~", 1) == 0) { 47 if (ut.ut_line[0] == '~') {
48 if (strncmp(ut.ut_user, "shutdown", 8) == 0) 48 if (strncmp(ut.ut_user, "shutdown", 8) == 0)
49 ut.ut_type = SHUTDOWN_TIME; 49 ut.ut_type = SHUTDOWN_TIME;
50 else if (strncmp(ut.ut_user, "reboot", 6) == 0) 50 else if (strncmp(ut.ut_user, "reboot", 6) == 0)
diff --git a/networking/inetd.c b/networking/inetd.c
index 4856b11ae..7c89be28f 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -759,7 +759,7 @@ static servtab_t *getconfigent(void)
759 while (nsep != NULL) { 759 while (nsep != NULL) {
760 nsep->se_checked = 1; 760 nsep->se_checked = 1;
761 if (nsep->se_family == AF_INET) { 761 if (nsep->se_family == AF_INET) {
762 if (!strcmp(nsep->se_hostaddr, "*")) 762 if (LONE_CHAR(nsep->se_hostaddr, '*'))
763 nsep->se_ctrladdr_in.sin_addr.s_addr = INADDR_ANY; 763 nsep->se_ctrladdr_in.sin_addr.s_addr = INADDR_ANY;
764 else if (!inet_aton(nsep->se_hostaddr, &nsep->se_ctrladdr_in.sin_addr)) { 764 else if (!inet_aton(nsep->se_hostaddr, &nsep->se_ctrladdr_in.sin_addr)) {
765 struct hostent *hp; 765 struct hostent *hp;
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index 9fb08e6ba..e6130e4d7 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -678,7 +678,7 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
678 if (brd_len) { 678 if (brd_len) {
679 duparg("broadcast", *argv); 679 duparg("broadcast", *argv);
680 } 680 }
681 if (strcmp(*argv, "+") == 0) { 681 if (LONE_CHAR(*argv, '+')) {
682 brd_len = -1; 682 brd_len = -1;
683 } 683 }
684 else if (LONE_DASH(*argv)) { 684 else if (LONE_DASH(*argv)) {
diff --git a/shell/ash.c b/shell/ash.c
index 97f0d6bef..591e0a658 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -8172,7 +8172,7 @@ exitcmd(int argc, char **argv)
8172static int 8172static int
8173echocmd(int argc, char **argv) 8173echocmd(int argc, char **argv)
8174{ 8174{
8175 return bb_echo(argc, argv); 8175 return bb_echo(argv);
8176} 8176}
8177#endif 8177#endif
8178 8178