RFC: sh -c implied .exe suffix patch
Jason Tishler
jason@tishler.net
Tue Jul 30 08:52:00 GMT 2002
The attached patch, loosely inspired by a Cygwin specific patch to cp,
solves the following problem:
$ ls -ld foo*
drwxr-xr-x 2 jt Domain U 0 Jul 30 09:15 foo
-rwxr-xr-x 1 jt Domain U 17924 Jul 26 15:10 foo.exe
$ sh -c ./foo
./foo: not found
Note that bash does not have this problem:
$ bash -c ./foo
hello
After studying the source for ash, bash, and cygwin. I understand why
it works for bash but not for ash. Unfortunately, AFAICT, this problem
cannot be solved in the Cygwin DLL. So, I decided to develop a ash
workaround. With this patch, ash now behaves like bash for the above
test case:
$ sh -c ./foo
hello
Is the ash maintainer willing to accept this patch?
Thanks,
Jason
-------------- next part --------------
--- exec.c.orig 2002-07-29 16:00:41.000000000 -0400
+++ exec.c 2002-07-29 16:07:44.000000000 -0400
@@ -459,7 +459,22 @@ find_command(name, entry, printerr, path
(statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
entry->cmdtype = CMDNORMAL;
else
+#ifndef __CYGWIN__
entry->cmdtype = CMDUNKNOWN;
+#else
+ {
+ char *name_exe = 0;
+ name_exe = alloca(strlen(name) + 5);
+ strcpy(name_exe, name);
+ strcat(name_exe, ".exe");
+ if (stat(name_exe, &statb) == 0 &&
+ S_ISREG(statb.st_mode) &&
+ (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
+ entry->cmdtype = CMDNORMAL;
+ else
+ entry->cmdtype = CMDUNKNOWN;
+ }
+#endif /* !__CYGWIN__ */
entry->u.index = -1;
return;
}
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list