diff options
| author | Ron Yorston <rmy@pobox.com> | 2023-12-10 11:47:45 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2023-12-10 11:47:45 +0000 |
| commit | 5ff2bfefb4db527b201fa3059de2aa6e2139d9f9 (patch) | |
| tree | 6744c26a14d7d01380bd88aad95af41a000174a9 /libbb | |
| parent | 6bb25c4493268d24a3b82d3268b2adf624de88bd (diff) | |
| download | busybox-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')
| -rw-r--r-- | libbb/appletlib.c | 34 | ||||
| -rw-r--r-- | libbb/lineedit.c | 3 |
2 files changed, 24 insertions, 13 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 |
| 267 | int FAST_FUNC find_applet_by_name(const char *name) | 267 | # undef find_applet_by_name_with_path |
| 268 | int 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 | |||
| 274 | int 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) |
| 276 | static int external_exists(const char *name) | 282 | static 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 | ||
| 285 | static int is_applet_preferred_by_var(const char *name, const char *var) | 291 | static 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 | ||
| 322 | int FAST_FUNC is_applet_preferred(const char *name) | 330 | int 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 |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 1a118eb92..58ac68c22 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
| @@ -975,7 +975,8 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type) | |||
| 975 | # if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1 | 975 | # if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1 |
| 976 | const char *p = applet_names; | 976 | const char *p = applet_names; |
| 977 | while (*p) { | 977 | while (*p) { |
| 978 | if (strncmp(basecmd, p, baselen) == 0 && is_applet_preferred(p)) | 978 | if (strncmp(basecmd, p, baselen) == 0 && |
| 979 | is_applet_preferred(p, NULL)) | ||
| 979 | add_match(xstrdup(p), TRUE); | 980 | add_match(xstrdup(p), TRUE); |
| 980 | while (*p++ != '\0') | 981 | while (*p++ != '\0') |
| 981 | continue; | 982 | continue; |
