diff options
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 60 |
1 files changed, 8 insertions, 52 deletions
diff --git a/shell/ash.c b/shell/ash.c index cbe30a78b..587cf2abb 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -8405,7 +8405,7 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c | |||
8405 | 8405 | ||
8406 | #if ENABLE_PLATFORM_MINGW32 | 8406 | #if ENABLE_PLATFORM_MINGW32 |
8407 | { | 8407 | { |
8408 | char *new_cmd = add_win32_extension(cmd); | 8408 | char *new_cmd = alloc_win32_extension(cmd); |
8409 | execve(new_cmd ? new_cmd : cmd, argv, envp); | 8409 | execve(new_cmd ? new_cmd : cmd, argv, envp); |
8410 | free(new_cmd); | 8410 | free(new_cmd); |
8411 | } | 8411 | } |
@@ -8516,9 +8516,6 @@ printentry(struct tblentry *cmdp) | |||
8516 | int idx; | 8516 | int idx; |
8517 | const char *path; | 8517 | const char *path; |
8518 | char *name; | 8518 | char *name; |
8519 | #if ENABLE_PLATFORM_MINGW32 | ||
8520 | char *n; | ||
8521 | #endif | ||
8522 | 8519 | ||
8523 | idx = cmdp->param.index; | 8520 | idx = cmdp->param.index; |
8524 | path = pathval(); | 8521 | path = pathval(); |
@@ -8527,13 +8524,9 @@ printentry(struct tblentry *cmdp) | |||
8527 | stunalloc(name); | 8524 | stunalloc(name); |
8528 | } while (--idx >= 0); | 8525 | } while (--idx >= 0); |
8529 | #if ENABLE_PLATFORM_MINGW32 | 8526 | #if ENABLE_PLATFORM_MINGW32 |
8530 | if ((n=add_win32_extension(name)) != NULL) | 8527 | add_win32_extension(name); |
8531 | name = n; | ||
8532 | #endif | 8528 | #endif |
8533 | out1fmt("%s%s\n", name, (cmdp->rehash ? "*" : nullstr)); | 8529 | out1fmt("%s%s\n", name, (cmdp->rehash ? "*" : nullstr)); |
8534 | #if ENABLE_PLATFORM_MINGW32 | ||
8535 | free(n); | ||
8536 | #endif | ||
8537 | } | 8530 | } |
8538 | 8531 | ||
8539 | /* | 8532 | /* |
@@ -8921,9 +8914,6 @@ describe_command(char *command, const char *path, int describe_command_verbose) | |||
8921 | case CMDNORMAL: { | 8914 | case CMDNORMAL: { |
8922 | int j = entry.u.index; | 8915 | int j = entry.u.index; |
8923 | char *p; | 8916 | char *p; |
8924 | #if ENABLE_PLATFORM_MINGW32 | ||
8925 | char *q; | ||
8926 | #endif | ||
8927 | if (j < 0) { | 8917 | if (j < 0) { |
8928 | p = command; | 8918 | p = command; |
8929 | } else { | 8919 | } else { |
@@ -8933,17 +8923,13 @@ describe_command(char *command, const char *path, int describe_command_verbose) | |||
8933 | } while (--j >= 0); | 8923 | } while (--j >= 0); |
8934 | } | 8924 | } |
8935 | #if ENABLE_PLATFORM_MINGW32 | 8925 | #if ENABLE_PLATFORM_MINGW32 |
8936 | if ((q=add_win32_extension(p)) != NULL) | 8926 | add_win32_extension(p); |
8937 | p = q; | ||
8938 | #endif | 8927 | #endif |
8939 | if (describe_command_verbose) { | 8928 | if (describe_command_verbose) { |
8940 | out1fmt(" is %s", p); | 8929 | out1fmt(" is %s", p); |
8941 | } else { | 8930 | } else { |
8942 | out1str(p); | 8931 | out1str(p); |
8943 | } | 8932 | } |
8944 | #if ENABLE_PLATFORM_MINGW32 | ||
8945 | free(q); | ||
8946 | #endif | ||
8947 | break; | 8933 | break; |
8948 | } | 8934 | } |
8949 | 8935 | ||
@@ -13826,36 +13812,28 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
13826 | struct tblentry *cmdp; | 13812 | struct tblentry *cmdp; |
13827 | int idx; | 13813 | int idx; |
13828 | int prev; | 13814 | int prev; |
13829 | char *fullname IF_PLATFORM_MINGW32(= NULL); | 13815 | char *fullname; |
13830 | struct stat statb; | 13816 | struct stat statb; |
13831 | int e; | 13817 | int e; |
13832 | int updatetbl; | 13818 | int updatetbl; |
13833 | struct builtincmd *bcmd; | 13819 | struct builtincmd *bcmd; |
13834 | #if ENABLE_PLATFORM_MINGW32 | ||
13835 | extern const char win_suffix[4][4]; | ||
13836 | int i, len; | ||
13837 | #endif | ||
13838 | 13820 | ||
13839 | /* If name contains a slash, don't use PATH or hash table */ | 13821 | /* If name contains a slash, don't use PATH or hash table */ |
13840 | if (strchr(name, '/') || (ENABLE_PLATFORM_MINGW32 && strchr(name, '\\'))) { | 13822 | if (strchr(name, '/') || (ENABLE_PLATFORM_MINGW32 && strchr(name, '\\'))) { |
13841 | entry->u.index = -1; | 13823 | entry->u.index = -1; |
13842 | if (act & DO_ABS) { | 13824 | if (act & DO_ABS) { |
13843 | #if ENABLE_PLATFORM_MINGW32 | 13825 | #if ENABLE_PLATFORM_MINGW32 |
13844 | while ((fullname=add_win32_extension(name)) == NULL && | 13826 | if (auto_win32_extension(name) == NULL && stat(name, &statb) < 0) { |
13845 | stat(name, &statb) < 0 ) { | ||
13846 | #else | 13827 | #else |
13847 | while (stat(name, &statb) < 0) { | 13828 | while (stat(name, &statb) < 0) { |
13848 | #endif | ||
13849 | #ifdef SYSV | 13829 | #ifdef SYSV |
13850 | if (errno == EINTR) | 13830 | if (errno == EINTR) |
13851 | continue; | 13831 | continue; |
13852 | #endif | 13832 | #endif |
13833 | #endif | ||
13853 | entry->cmdtype = CMDUNKNOWN; | 13834 | entry->cmdtype = CMDUNKNOWN; |
13854 | return; | 13835 | return; |
13855 | } | 13836 | } |
13856 | #if ENABLE_PLATFORM_MINGW32 | ||
13857 | free(fullname); | ||
13858 | #endif | ||
13859 | } | 13837 | } |
13860 | entry->cmdtype = CMDNORMAL; | 13838 | entry->cmdtype = CMDNORMAL; |
13861 | return; | 13839 | return; |
@@ -13959,29 +13937,8 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
13959 | goto success; | 13937 | goto success; |
13960 | } | 13938 | } |
13961 | #if ENABLE_PLATFORM_MINGW32 | 13939 | #if ENABLE_PLATFORM_MINGW32 |
13962 | /* first try appending suffixes (unless there's one already) */ | 13940 | add_win32_extension(fullname); |
13963 | i = 4; | 13941 | #endif |
13964 | len = strlen(fullname); | ||
13965 | if (!has_exe_suffix_or_dot(fullname)) { | ||
13966 | /* path_advance() has reserved space for suffix */ | ||
13967 | fullname[len] = '.'; | ||
13968 | for (i=0; i<4; ++i) { | ||
13969 | memcpy(fullname+len+1, win_suffix[i], 4); | ||
13970 | if (stat(fullname, &statb) == 0) | ||
13971 | break; | ||
13972 | } | ||
13973 | } | ||
13974 | |||
13975 | if (i == 4) { | ||
13976 | /* adding a suffix failed (or wasn't tried), try original */ | ||
13977 | fullname[len] = '\0'; | ||
13978 | if (stat(fullname, &statb) < 0) { | ||
13979 | if (errno != ENOENT && errno != ENOTDIR) | ||
13980 | e = errno; | ||
13981 | goto loop; | ||
13982 | } | ||
13983 | } | ||
13984 | #else | ||
13985 | while (stat(fullname, &statb) < 0) { | 13942 | while (stat(fullname, &statb) < 0) { |
13986 | #ifdef SYSV | 13943 | #ifdef SYSV |
13987 | if (errno == EINTR) | 13944 | if (errno == EINTR) |
@@ -13991,7 +13948,6 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
13991 | e = errno; | 13948 | e = errno; |
13992 | goto loop; | 13949 | goto loop; |
13993 | } | 13950 | } |
13994 | #endif | ||
13995 | e = EACCES; /* if we fail, this will be the error */ | 13951 | e = EACCES; /* if we fail, this will be the error */ |
13996 | if (!S_ISREG(statb.st_mode)) | 13952 | if (!S_ISREG(statb.st_mode)) |
13997 | continue; | 13953 | continue; |