aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-06-19 10:06:11 +0100
committerRon Yorston <rmy@pobox.com>2023-06-19 10:27:08 +0100
commit3c910ba8be077e4702b040e5a7d445e1b9d85695 (patch)
tree0aba194c1982024951bb3312ca44bed53ddf5288
parent4b3d7e62cff6015e1c4b856165efd90cf9182a5c (diff)
downloadbusybox-w32-3c910ba8be077e4702b040e5a7d445e1b9d85695.tar.gz
busybox-w32-3c910ba8be077e4702b040e5a7d445e1b9d85695.tar.bz2
busybox-w32-3c910ba8be077e4702b040e5a7d445e1b9d85695.zip
win32: more applet look-up tweaks
When an applet is overridden by BB_OVERRIDE_APPLETS it should still function in certain cases: busybox applet applet.exe busybox --help applet Arrange for this by adding really_find_applet_by_name() as a static function in libbb/appletlib.c. find_applet_by_name() is implemented using this for external use while really_find_applet_by_name() is used internally in some instances. Adds 32 bytes. (GitHub issue #329)
-rw-r--r--libbb/appletlib.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index a378846b9..9a291a93a 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -100,6 +100,11 @@ static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS };
100# define ENABLE_FEATURE_COMPRESS_USAGE 0 100# define ENABLE_FEATURE_COMPRESS_USAGE 0
101#endif 101#endif
102 102
103#if ENABLE_PLATFORM_MINGW32
104static int really_find_applet_by_name(const char *name);
105#else
106#define really_find_applet_by_name(n) find_applet_by_name(n)
107#endif
103 108
104unsigned FAST_FUNC string_array_len(char **argv) 109unsigned FAST_FUNC string_array_len(char **argv)
105{ 110{
@@ -156,7 +161,7 @@ void FAST_FUNC bb_show_usage(void)
156#else 161#else
157 const char *p; 162 const char *p;
158 const char *usage_string = p = unpack_usage_messages(); 163 const char *usage_string = p = unpack_usage_messages();
159 int ap = find_applet_by_name(applet_name); 164 int ap = really_find_applet_by_name(applet_name);
160 165
161 if (ap < 0 || usage_string == NULL) 166 if (ap < 0 || usage_string == NULL)
162 xfunc_die(); 167 xfunc_die();
@@ -189,7 +194,11 @@ void FAST_FUNC bb_show_usage(void)
189 xfunc_die(); 194 xfunc_die();
190} 195}
191 196
197#if ENABLE_PLATFORM_MINGW32
198static int really_find_applet_by_name(const char *name)
199#else
192int FAST_FUNC find_applet_by_name(const char *name) 200int FAST_FUNC find_applet_by_name(const char *name)
201#endif
193{ 202{
194 unsigned i; 203 unsigned i;
195 int j; 204 int j;
@@ -238,7 +247,7 @@ int FAST_FUNC find_applet_by_name(const char *name)
238 for (j = 0; *p == name[j]; ++j) { 247 for (j = 0; *p == name[j]; ++j) {
239 if (*p++ == '\0') { 248 if (*p++ == '\0') {
240 //bb_error_msg("found:'%s' i:%u", name, i); 249 //bb_error_msg("found:'%s' i:%u", name, i);
241 return is_applet_preferred(name) ? i : -1; /* yes */ 250 return i; /* yes */
242 } 251 }
243 } 252 }
244 /* No. Have we gone too far, alphabetically? */ 253 /* No. Have we gone too far, alphabetically? */
@@ -254,6 +263,14 @@ int FAST_FUNC find_applet_by_name(const char *name)
254 return -1; 263 return -1;
255} 264}
256 265
266#if ENABLE_PLATFORM_MINGW32
267int FAST_FUNC find_applet_by_name(const char *name)
268{
269 int applet_no = really_find_applet_by_name(name);
270 return applet_no >= 0 && is_applet_preferred(name) ? applet_no : -1;
271}
272#endif
273
257#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \ 274#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \
258 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) 275 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
259static int external_exists(const char *name) 276static int external_exists(const char *name)
@@ -1080,7 +1097,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
1080 /* convert to "<applet> --help" */ 1097 /* convert to "<applet> --help" */
1081 applet_name = argv[0] = argv[2]; 1098 applet_name = argv[0] = argv[2];
1082 argv[2] = NULL; 1099 argv[2] = NULL;
1083 if (find_applet_by_name(applet_name) >= 0) { 1100 if (really_find_applet_by_name(applet_name) >= 0) {
1084 /* Make "--help foo" exit with 0: */ 1101 /* Make "--help foo" exit with 0: */
1085 xfunc_error_retval = 0; 1102 xfunc_error_retval = 0;
1086 bb_show_usage(); 1103 bb_show_usage();
@@ -1189,7 +1206,7 @@ static NORETURN void run_applet_and_exit(const char *name, char **argv)
1189# if NUM_APPLETS > 0 1206# if NUM_APPLETS > 0
1190 /* find_applet_by_name() search is more expensive, so goes second */ 1207 /* find_applet_by_name() search is more expensive, so goes second */
1191 { 1208 {
1192 int applet = find_applet_by_name(name); 1209 int applet = really_find_applet_by_name(name);
1193 if (applet >= 0) 1210 if (applet >= 0)
1194 run_applet_no_and_exit(applet, name, argv); 1211 run_applet_no_and_exit(applet, name, argv);
1195 } 1212 }