diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-01-17 11:02:21 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-01-17 11:02:43 +0100 |
commit | 5d78355d5afcda9a95cb18926317e86f8b14223e (patch) | |
tree | 8714a6d7c9519a053d92f3e6946dd72e56c8d539 /libbb/appletlib.c | |
parent | 5ca853e5dab665efef99f3b6690015977ff90572 (diff) | |
download | busybox-w32-5d78355d5afcda9a95cb18926317e86f8b14223e.tar.gz busybox-w32-5d78355d5afcda9a95cb18926317e86f8b14223e.tar.bz2 busybox-w32-5d78355d5afcda9a95cb18926317e86f8b14223e.zip |
code shrink
function old new delta
applet_name_compare 36 31 -5
find_applet_by_name 43 25 -18
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r-- | libbb/appletlib.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index da13bf36c..67df44690 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -140,10 +140,9 @@ void FAST_FUNC bb_show_usage(void) | |||
140 | } | 140 | } |
141 | 141 | ||
142 | #if NUM_APPLETS > 8 | 142 | #if NUM_APPLETS > 8 |
143 | /* NB: any char pointer will work as well, not necessarily applet_names */ | 143 | static int applet_name_compare(const void *name, const void *idx) |
144 | static int applet_name_compare(const void *name, const void *v) | ||
145 | { | 144 | { |
146 | int i = (const char *)v - applet_names; | 145 | int i = (int)(ptrdiff_t)idx - 1; |
147 | return strcmp(name, APPLET_NAME(i)); | 146 | return strcmp(name, APPLET_NAME(i)); |
148 | } | 147 | } |
149 | #endif | 148 | #endif |
@@ -152,10 +151,12 @@ int FAST_FUNC find_applet_by_name(const char *name) | |||
152 | #if NUM_APPLETS > 8 | 151 | #if NUM_APPLETS > 8 |
153 | /* Do a binary search to find the applet entry given the name. */ | 152 | /* Do a binary search to find the applet entry given the name. */ |
154 | const char *p; | 153 | const char *p; |
155 | p = bsearch(name, applet_names, ARRAY_SIZE(applet_main), 1, applet_name_compare); | 154 | p = bsearch(name, (void*)(ptrdiff_t)1, ARRAY_SIZE(applet_main), 1, applet_name_compare); |
156 | if (!p) | 155 | /* |
157 | return -1; | 156 | * if (!p) return -1; |
158 | return p - applet_names; | 157 | * ^^^^^^^^^^^^^^^^^^ the code below will do this if p == NULL :) |
158 | */ | ||
159 | return (int)(ptrdiff_t)p - 1; | ||
159 | #else | 160 | #else |
160 | /* A version which does not pull in bsearch */ | 161 | /* A version which does not pull in bsearch */ |
161 | int i = 0; | 162 | int i = 0; |
@@ -747,8 +748,11 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) | |||
747 | /* Special case. POSIX says "test --help" | 748 | /* Special case. POSIX says "test --help" |
748 | * should be no different from e.g. "test --foo". */ | 749 | * should be no different from e.g. "test --foo". */ |
749 | //TODO: just compare applet_no with APPLET_NO_test | 750 | //TODO: just compare applet_no with APPLET_NO_test |
750 | if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) | 751 | if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) { |
752 | /* If you want "foo --help" to return 0: */ | ||
753 | /*xfunc_error_retval = 0;*/ | ||
751 | bb_show_usage(); | 754 | bb_show_usage(); |
755 | } | ||
752 | } | 756 | } |
753 | if (ENABLE_FEATURE_SUID) | 757 | if (ENABLE_FEATURE_SUID) |
754 | check_suid(applet_no); | 758 | check_suid(applet_no); |