aboutsummaryrefslogtreecommitdiff
path: root/libbb/appletlib.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-12-10 11:47:45 +0000
committerRon Yorston <rmy@pobox.com>2023-12-10 11:47:45 +0000
commit5ff2bfefb4db527b201fa3059de2aa6e2139d9f9 (patch)
tree6744c26a14d7d01380bd88aad95af41a000174a9 /libbb/appletlib.c
parent6bb25c4493268d24a3b82d3268b2adf624de88bd (diff)
downloadbusybox-w32-5ff2bfefb4db527b201fa3059de2aa6e2139d9f9.tar.gz
busybox-w32-5ff2bfefb4db527b201fa3059de2aa6e2139d9f9.tar.bz2
busybox-w32-5ff2bfefb4db527b201fa3059de2aa6e2139d9f9.zip
win32: code shrink applet overrides
Pass the PATH to be used to look up executables down from the shell to the applet override code. This replaces the use of a static variable and a function to fetch its value. Saves 16-32 bytes.
Diffstat (limited to 'libbb/appletlib.c')
-rw-r--r--libbb/appletlib.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 3c9cebf1e..5cd2bbcc2 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -264,25 +264,32 @@ int FAST_FUNC find_applet_by_name(const char *name)
264} 264}
265 265
266#if ENABLE_PLATFORM_MINGW32 266#if ENABLE_PLATFORM_MINGW32
267int FAST_FUNC find_applet_by_name(const char *name) 267# undef find_applet_by_name_with_path
268int FAST_FUNC find_applet_by_name_with_path(const char *name, const char *path)
268{ 269{
269 int applet_no = really_find_applet_by_name(name); 270 int applet_no = really_find_applet_by_name(name);
270 return applet_no >= 0 && is_applet_preferred(name) ? applet_no : -1; 271 return applet_no >= 0 && is_applet_preferred(name, path) ? applet_no : -1;
272}
273
274int FAST_FUNC find_applet_by_name(const char *name)
275{
276 return find_applet_by_name_with_path(name, NULL);
271} 277}
272#endif 278#endif
273 279
274#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \ 280#if ENABLE_PLATFORM_MINGW32 && NUM_APPLETS > 1 && \
275 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE) 281 (ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE)
276static int external_exists(const char *name) 282static int external_exists(const char *name, const char *path)
277{ 283{
278 const char *ash_path = get_ash_path(); 284 char *path1 = xstrdup(path ?: getenv("PATH"));
279 char *path = ash_path ? auto_string(xstrdup(ash_path)) : getenv("PATH"); 285 char *ret = find_executable(name, &path1);
280 char *ret = find_executable(name, &path);
281 free(ret); 286 free(ret);
287 free(path1);
282 return ret != NULL; 288 return ret != NULL;
283} 289}
284 290
285static int is_applet_preferred_by_var(const char *name, const char *var) 291static int is_applet_preferred_by_var(const char *name, const char *path,
292 const char *var)
286{ 293{
287 const char *s, *sep; 294 const char *s, *sep;
288 size_t len; 295 size_t len;
@@ -294,7 +301,7 @@ static int is_applet_preferred_by_var(const char *name, const char *var)
294 301
295 /* '+' each applet is overridden if an external command exists */ 302 /* '+' each applet is overridden if an external command exists */
296 if (var[0] == '+' && var[1] == '\0') 303 if (var[0] == '+' && var[1] == '\0')
297 return !external_exists(name); 304 return !external_exists(name, path);
298 305
299 /* Handle applets from a list separated by spaces, commas or 306 /* Handle applets from a list separated by spaces, commas or
300 * semicolons. Applets before the first semicolon are disabled. 307 * semicolons. Applets before the first semicolon are disabled.
@@ -313,17 +320,20 @@ static int is_applet_preferred_by_var(const char *name, const char *var)
313 /* neither "..name" nor "..name,xxx"? */ 320 /* neither "..name" nor "..name,xxx"? */
314 if (s[len] != '\0' && !strchr(" ,;", s[len])) 321 if (s[len] != '\0' && !strchr(" ,;", s[len]))
315 continue; 322 continue;
316 return (sep == NULL || s < sep) ? FALSE : !external_exists(name); 323 return (sep == NULL || s < sep) ?
324 FALSE : !external_exists(name, path);
317 } 325 }
318 } 326 }
319 return TRUE; 327 return TRUE;
320} 328}
321 329
322int FAST_FUNC is_applet_preferred(const char *name) 330int FAST_FUNC is_applet_preferred(const char *name, const char *path)
323{ 331{
324 int ret = is_applet_preferred_by_var(name, getenv(BB_OVERRIDE_APPLETS)); 332 int ret;
333
334 ret = is_applet_preferred_by_var(name, path, getenv(BB_OVERRIDE_APPLETS));
325 if (sizeof(CONFIG_OVERRIDE_APPLETS) > 1 && ret) 335 if (sizeof(CONFIG_OVERRIDE_APPLETS) > 1 && ret)
326 ret = is_applet_preferred_by_var(name, CONFIG_OVERRIDE_APPLETS); 336 ret = is_applet_preferred_by_var(name, path, CONFIG_OVERRIDE_APPLETS);
327 return ret; 337 return ret;
328} 338}
329#endif 339#endif