aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index aa442144a..8d58ce2ea 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -76,6 +76,13 @@ static inline int *get_perrno(void) { return &errno; }
76static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS }; 76static const char packed_scripts[] ALIGN1 = { PACKED_SCRIPTS };
77#endif 77#endif
78 78
79#if defined(find_applet_by_name)
80# undef find_applet_by_name
81#endif
82#if defined(is_applet_preferred)
83# undef is_applet_preferred
84#endif
85
79/* "Do not compress usage text if uncompressed text is small 86/* "Do not compress usage text if uncompressed text is small
80 * and we don't include bunzip2 code for other reasons" 87 * and we don't include bunzip2 code for other reasons"
81 * 88 *
@@ -254,6 +261,45 @@ int FAST_FUNC find_applet_by_name(const char *name)
254 return -1; 261 return -1;
255} 262}
256 263
264#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \
265 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
266int FAST_FUNC is_applet_preferred(const char *name)
267{
268 const char *var, *s;
269 size_t len;
270
271 var = getenv("BB_OVERRIDE_APPLETS");
272 if (var && *var) {
273 /* '-' overrides all applets */
274 if (var[0] == '-' && var[1] == '\0')
275 return FALSE;
276
277 /* Override applets from a space-separated list */
278 len = strlen(name);
279 s = var - 1;
280 while (1) {
281 s = strstr(s + 1, name);
282 if (!s)
283 break;
284 /* neither "name.." nor "xxx,name.."? */
285 if (s != var && s[-1] != ' ')
286 continue;
287 /* neither "..name" nor "..name,xxx"? */
288 if (s[len] != '\0' && s[len] != ' ')
289 continue;
290 return FALSE;
291 }
292 }
293 return TRUE;
294}
295
296int FAST_FUNC find_preferred_applet_by_name(const char *name)
297{
298 int applet_no = find_applet_by_name(name);
299 return applet_no >= 0 && is_applet_preferred(name) ? applet_no : -1;
300}
301#endif
302
257 303
258void lbb_prepare(const char *applet 304void lbb_prepare(const char *applet
259 IF_FEATURE_INDIVIDUAL(, char **argv)) 305 IF_FEATURE_INDIVIDUAL(, char **argv))