diff options
author | Ron Yorston <rmy@pobox.com> | 2017-08-28 19:04:26 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2017-08-30 17:17:14 +0100 |
commit | 862e1bd8d6117d5b44e3ab431b3a6837d8e44040 (patch) | |
tree | 925f6a6e2f9d676fe20a63f00bbcd1595a895c3e /shell | |
parent | 0599746d9bcf513c4898cbd1a46ef1d5b3478627 (diff) | |
download | busybox-w32-862e1bd8d6117d5b44e3ab431b3a6837d8e44040.tar.gz busybox-w32-862e1bd8d6117d5b44e3ab431b3a6837d8e44040.tar.bz2 busybox-w32-862e1bd8d6117d5b44e3ab431b3a6837d8e44040.zip |
win32: shrink code to detect .exe files
Add a function (has_exe_suffix) to replace explicit code to check
if a filename ends with '.exe. or '.com'.
Also shrink code that checks for '.exe' or '.com' on PATH in shell's
find_command function.
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c index af0c68dcf..e47836d70 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -13564,10 +13564,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
13564 | goto success; | 13564 | goto success; |
13565 | } | 13565 | } |
13566 | #if ENABLE_PLATFORM_MINGW32 | 13566 | #if ENABLE_PLATFORM_MINGW32 |
13567 | len = strlen(fullname); | 13567 | if (has_exe_suffix(fullname)) { |
13568 | if (len > 4 && | ||
13569 | (!strcasecmp(fullname+len-4, ".exe") || | ||
13570 | !strcasecmp(fullname+len-4, ".com"))) { | ||
13571 | if (stat(fullname, &statb) < 0) { | 13568 | if (stat(fullname, &statb) < 0) { |
13572 | if (errno != ENOENT && errno != ENOTDIR) | 13569 | if (errno != ENOENT && errno != ENOTDIR) |
13573 | e = errno; | 13570 | e = errno; |
@@ -13576,14 +13573,12 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
13576 | } | 13573 | } |
13577 | else { | 13574 | else { |
13578 | /* path_advance() has reserved space for .exe */ | 13575 | /* path_advance() has reserved space for .exe */ |
13579 | memcpy(fullname+len, ".exe", 5); | 13576 | len = strlen(fullname); |
13577 | strcat(fullname, ".exe"); | ||
13580 | if (stat(fullname, &statb) < 0) { | 13578 | if (stat(fullname, &statb) < 0) { |
13581 | if (errno != ENOENT && errno != ENOTDIR) | ||
13582 | e = errno; | ||
13583 | memcpy(fullname+len, ".com", 5); | 13579 | memcpy(fullname+len, ".com", 5); |
13584 | if (stat(fullname, &statb) < 0) { | 13580 | if (stat(fullname, &statb) < 0) { |
13585 | if (errno != ENOENT && errno != ENOTDIR) | 13581 | /* check for script */ |
13586 | e = errno; | ||
13587 | fullname[len] = '\0'; | 13582 | fullname[len] = '\0'; |
13588 | if (stat(fullname, &statb) < 0) { | 13583 | if (stat(fullname, &statb) < 0) { |
13589 | if (errno != ENOENT && errno != ENOTDIR) | 13584 | if (errno != ENOENT && errno != ENOTDIR) |