From 862e1bd8d6117d5b44e3ab431b3a6837d8e44040 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 28 Aug 2017 19:04:26 +0100 Subject: 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. --- shell/ash.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'shell') 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) goto success; } #if ENABLE_PLATFORM_MINGW32 - len = strlen(fullname); - if (len > 4 && - (!strcasecmp(fullname+len-4, ".exe") || - !strcasecmp(fullname+len-4, ".com"))) { + if (has_exe_suffix(fullname)) { if (stat(fullname, &statb) < 0) { if (errno != ENOENT && errno != ENOTDIR) e = errno; @@ -13576,14 +13573,12 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) } else { /* path_advance() has reserved space for .exe */ - memcpy(fullname+len, ".exe", 5); + len = strlen(fullname); + strcat(fullname, ".exe"); if (stat(fullname, &statb) < 0) { - if (errno != ENOENT && errno != ENOTDIR) - e = errno; memcpy(fullname+len, ".com", 5); if (stat(fullname, &statb) < 0) { - if (errno != ENOENT && errno != ENOTDIR) - e = errno; + /* check for script */ fullname[len] = '\0'; if (stat(fullname, &statb) < 0) { if (errno != ENOENT && errno != ENOTDIR) -- cgit v1.2.3-55-g6feb