diff options
author | Ron Yorston <rmy@pobox.com> | 2013-02-07 14:25:54 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2013-02-07 14:25:54 +0000 |
commit | b604585914e032b28bef3e337a978e56a9069cda (patch) | |
tree | b2ee0a3fb38d10397c602d0fe215ea3bbbf334c0 /libbb/appletlib.c | |
parent | 0eda07c7ff8cf1fc11bc1bda5383f884d7adf031 (diff) | |
parent | ba76b7a40b929878833731f76306b1c977cc8650 (diff) | |
download | busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.tar.gz busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.tar.bz2 busybox-w32-b604585914e032b28bef3e337a978e56a9069cda.zip |
Merge branch 'busybox' into merge
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 63ec010dd..fb06ab9a5 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; |
@@ -749,8 +750,11 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv) | |||
749 | /* Special case. POSIX says "test --help" | 750 | /* Special case. POSIX says "test --help" |
750 | * should be no different from e.g. "test --foo". */ | 751 | * should be no different from e.g. "test --foo". */ |
751 | //TODO: just compare applet_no with APPLET_NO_test | 752 | //TODO: just compare applet_no with APPLET_NO_test |
752 | if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) | 753 | if (!ENABLE_TEST || strcmp(applet_name, "test") != 0) { |
754 | /* If you want "foo --help" to return 0: */ | ||
755 | /*xfunc_error_retval = 0;*/ | ||
753 | bb_show_usage(); | 756 | bb_show_usage(); |
757 | } | ||
754 | } | 758 | } |
755 | if (ENABLE_FEATURE_SUID) | 759 | if (ENABLE_FEATURE_SUID) |
756 | check_suid(applet_no); | 760 | check_suid(applet_no); |