diff options
author | Ron Yorston <rmy@pobox.com> | 2020-08-13 11:36:29 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-08-13 14:58:01 +0100 |
commit | 258ad6a1d52f1811f9de1d6b976f3797f5b31a2b (patch) | |
tree | e195bfa9eccb187e3e83ef797f516a92b539787e | |
parent | 5a48290d9bdb827657114c24aa75c67bb1bd0ea7 (diff) | |
download | busybox-w32-258ad6a1d52f1811f9de1d6b976f3797f5b31a2b.tar.gz busybox-w32-258ad6a1d52f1811f9de1d6b976f3797f5b31a2b.tar.bz2 busybox-w32-258ad6a1d52f1811f9de1d6b976f3797f5b31a2b.zip |
win32: code shrink
Add a new function, has_path(), to detect that an executable name
doesn't require a path look-up.
Also, since is_absolute_path() is now only used in shell/ash.c move
its definition there from include/mingw.h.
Saves 128 bytes.
-rw-r--r-- | debianutils/which.c | 3 | ||||
-rw-r--r-- | include/mingw.h | 2 | ||||
-rw-r--r-- | shell/ash.c | 9 | ||||
-rw-r--r-- | win32/mingw.c | 8 | ||||
-rw-r--r-- | win32/process.c | 2 |
5 files changed, 17 insertions, 7 deletions
diff --git a/debianutils/which.c b/debianutils/which.c index 590d50683..1f8c1a538 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
@@ -70,8 +70,7 @@ int which_main(int argc UNUSED_PARAM, char **argv) | |||
70 | #if !ENABLE_PLATFORM_MINGW32 | 70 | #if !ENABLE_PLATFORM_MINGW32 |
71 | if (strchr(*argv, '/')) { | 71 | if (strchr(*argv, '/')) { |
72 | #else | 72 | #else |
73 | if (strchr(*argv, '/') || strchr(*argv, '\\') || | 73 | if (has_path(*argv)) { |
74 | has_dos_drive_prefix(*argv)) { | ||
75 | if ((p=auto_win32_extension(*argv)) != NULL) { | 74 | if ((p=auto_win32_extension(*argv)) != NULL) { |
76 | missing = 0; | 75 | missing = 0; |
77 | puts(bs_to_slash(p)); | 76 | puts(bs_to_slash(p)); |
diff --git a/include/mingw.h b/include/mingw.h index 16f0396db..5c0b0a7f4 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -501,7 +501,6 @@ int mingw_execve(const char *cmd, char *const *argv, char *const *envp); | |||
501 | #define execv mingw_execv | 501 | #define execv mingw_execv |
502 | 502 | ||
503 | #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') | 503 | #define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') |
504 | #define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path)) | ||
505 | 504 | ||
506 | int kill_SIGTERM_by_handle(HANDLE process); | 505 | int kill_SIGTERM_by_handle(HANDLE process); |
507 | 506 | ||
@@ -554,3 +553,4 @@ char *get_drive_cwd(const char *path, char *buffer, int size); | |||
554 | void fix_path_case(char *path); | 553 | void fix_path_case(char *path); |
555 | void make_sparse(int fd, off_t start, off_t end); | 554 | void make_sparse(int fd, off_t start, off_t end); |
556 | int skip_ansi_emulation(int reset); | 555 | int skip_ansi_emulation(int reset); |
556 | int has_path(const char *file); | ||
diff --git a/shell/ash.c b/shell/ash.c index d35ae027f..db7b18957 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -322,6 +322,8 @@ typedef long arith_t; | |||
322 | 322 | ||
323 | #if !ENABLE_PLATFORM_MINGW32 | 323 | #if !ENABLE_PLATFORM_MINGW32 |
324 | # define is_absolute_path(path) ((path)[0] == '/') | 324 | # define is_absolute_path(path) ((path)[0] == '/') |
325 | #else | ||
326 | # define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path)) | ||
325 | #endif | 327 | #endif |
326 | 328 | ||
327 | #if !BB_MMU | 329 | #if !BB_MMU |
@@ -8729,9 +8731,10 @@ static void shellexec(char *prog, char **argv, const char *path, int idx) | |||
8729 | int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */ | 8731 | int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */ |
8730 | 8732 | ||
8731 | envp = listvars(VEXPORT, VUNSET, /*strlist:*/ NULL, /*end:*/ NULL); | 8733 | envp = listvars(VEXPORT, VUNSET, /*strlist:*/ NULL, /*end:*/ NULL); |
8734 | #if !ENABLE_PLATFORM_MINGW32 | ||
8732 | if (strchr(prog, '/') != NULL | 8735 | if (strchr(prog, '/') != NULL |
8733 | #if ENABLE_PLATFORM_MINGW32 | 8736 | #else |
8734 | || strchr(prog, '\\') != NULL || has_dos_drive_prefix(prog) | 8737 | if (has_path(prog) |
8735 | #endif | 8738 | #endif |
8736 | #if ENABLE_FEATURE_SH_STANDALONE | 8739 | #if ENABLE_FEATURE_SH_STANDALONE |
8737 | || (applet_no = find_applet_by_name(prog)) >= 0 | 8740 | || (applet_no = find_applet_by_name(prog)) >= 0 |
@@ -14242,7 +14245,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
14242 | 14245 | ||
14243 | /* If name contains a slash, don't use PATH or hash table */ | 14246 | /* If name contains a slash, don't use PATH or hash table */ |
14244 | #if ENABLE_PLATFORM_MINGW32 | 14247 | #if ENABLE_PLATFORM_MINGW32 |
14245 | if (strchr(name, '/') || strchr(name, '\\') || has_dos_drive_prefix(name)) { | 14248 | if (has_path(name)) { |
14246 | #else | 14249 | #else |
14247 | if (strchr(name, '/') != NULL) { | 14250 | if (strchr(name, '/') != NULL) { |
14248 | #endif | 14251 | #endif |
diff --git a/win32/mingw.c b/win32/mingw.c index faa9f2b57..d9bb6e973 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1803,3 +1803,11 @@ void *get_proc_addr(const char *dll, const char *function, | |||
1803 | errno = ENOSYS; | 1803 | errno = ENOSYS; |
1804 | return proc->pfunction; | 1804 | return proc->pfunction; |
1805 | } | 1805 | } |
1806 | |||
1807 | /* Return true if file is referenced using a path. This means a path | ||
1808 | * look-up isn't required. */ | ||
1809 | int has_path(const char *file) | ||
1810 | { | ||
1811 | return strchr(file, '/') || strchr(file, '\\') || | ||
1812 | has_dos_drive_prefix(file); | ||
1813 | } | ||
diff --git a/win32/process.c b/win32/process.c index ac63a9c58..1118eb18a 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -348,7 +348,7 @@ mingw_spawn_1(int mode, const char *cmd, char *const *argv, char *const *envp) | |||
348 | return mingw_spawn_applet(mode, argv, envp); | 348 | return mingw_spawn_applet(mode, argv, envp); |
349 | else | 349 | else |
350 | #endif | 350 | #endif |
351 | if (strchr(cmd, '/') || strchr(cmd, '\\') || has_dos_drive_prefix(cmd)) { | 351 | if (has_path(cmd)) { |
352 | const char *path = auto_win32_extension(cmd); | 352 | const char *path = auto_win32_extension(cmd); |
353 | return mingw_spawn_interpreter(mode, path ? path : cmd, argv, envp, 0); | 353 | return mingw_spawn_interpreter(mode, path ? path : cmd, argv, envp, 0); |
354 | } | 354 | } |