aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-02-26 10:08:50 +0000
committerRon Yorston <rmy@pobox.com>2018-02-26 10:08:50 +0000
commit00f2d33f37da42e17e5d978958659c4899cb2f0a (patch)
tree5d43272aa7c6a4f3be2dd4f9e9d1edf3963ec69d /shell
parent7288179d1218f8e0308455d4d58346aec268eb2e (diff)
downloadbusybox-w32-00f2d33f37da42e17e5d978958659c4899cb2f0a.tar.gz
busybox-w32-00f2d33f37da42e17e5d978958659c4899cb2f0a.tar.bz2
busybox-w32-00f2d33f37da42e17e5d978958659c4899cb2f0a.zip
win32: add support for batch files
Support batch files with .bat and .cmd extensions, similar to what's done for .exe and .com. Check extensions in the same order as Windows' spawn function: .com, .exe, .bat, .cmd.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 4c9c76b8c..30f3b558b 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2620,7 +2620,7 @@ path_advance(const char **path, const char *name)
2620#endif 2620#endif
2621 len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */ 2621 len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */
2622 2622
2623 /* preserve space for .exe too */ 2623 /* reserve space for suffix on WIN32 */
2624 while (stackblocksize() < (ENABLE_PLATFORM_MINGW32 ? len+4 : len)) 2624 while (stackblocksize() < (ENABLE_PLATFORM_MINGW32 ? len+4 : len))
2625 growstackblock(); 2625 growstackblock();
2626 q = stackblock(); 2626 q = stackblock();
@@ -13646,7 +13646,6 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
13646 struct stat statb; 13646 struct stat statb;
13647 int e; 13647 int e;
13648 int updatetbl; 13648 int updatetbl;
13649 IF_PLATFORM_MINGW32(int len;)
13650 struct builtincmd *bcmd; 13649 struct builtincmd *bcmd;
13651 13650
13652 /* If name contains a slash, don't use PATH or hash table */ 13651 /* If name contains a slash, don't use PATH or hash table */
@@ -13779,26 +13778,31 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
13779 } 13778 }
13780 } 13779 }
13781 else { 13780 else {
13782 /* path_advance() has reserved space for .exe */ 13781 extern const char win_suffix[4][4];
13782 int i, len;
13783
13784 /* path_advance() has reserved space for suffix */
13783 len = strlen(fullname); 13785 len = strlen(fullname);
13784 strcat(fullname, ".exe"); 13786 fullname[len] = '.';
13785 if (stat(fullname, &statb) < 0) { 13787 for (i=0; i<4; ++i) {
13786 memcpy(fullname+len, ".com", 5); 13788 memcpy(fullname+len+1, win_suffix[i], 4);
13789 if (stat(fullname, &statb) == 0)
13790 break;
13791 }
13792 fullname[len] = '\0';
13793
13794 if (i == 4) {
13795 /* suffix didn't work, try without */
13787 if (stat(fullname, &statb) < 0) { 13796 if (stat(fullname, &statb) < 0) {
13788 /* check for script */ 13797 if (errno != ENOENT && errno != ENOTDIR)
13789 fullname[len] = '\0'; 13798 e = errno;
13790 if (stat(fullname, &statb) < 0) { 13799 goto loop;
13791 if (errno != ENOENT && errno != ENOTDIR) 13800 }
13792 e = errno; 13801 if (!file_is_executable(fullname)) {
13793 goto loop; 13802 e = ENOEXEC;
13794 } 13803 goto loop;
13795 if (!file_is_executable(fullname)) {
13796 e = ENOEXEC;
13797 goto loop;
13798 }
13799 } 13804 }
13800 } 13805 }
13801 fullname[len] = '\0';
13802 } 13806 }
13803#else 13807#else
13804 while (stat(fullname, &statb) < 0) { 13808 while (stat(fullname, &statb) < 0) {