summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 05:00:29 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 05:00:29 +0000
commitc56fa330b24863f5e946caf7846a1a8b44674e48 (patch)
tree569d2051661eb68dd8a1d42d71fd83f36251fa9c /win32
parent9247eb133be595b10a901bf13bbd886f77bf0cbb (diff)
* win32/win32.c (CreateChild): search executable file if no program
name given. (backported from CVS HEAD) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 6229cba962..78e40a6c96 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -852,15 +852,17 @@ char **argv;
}
static struct ChildRecord *
-CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HANDLE hOutput, HANDLE hError)
+CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
+ HANDLE hInput, HANDLE hOutput, HANDLE hError)
{
BOOL fRet;
DWORD dwCreationFlags;
STARTUPINFO aStartupInfo;
PROCESS_INFORMATION aProcessInformation;
SECURITY_ATTRIBUTES sa;
- char *shell;
+ const char *shell;
struct ChildRecord *child;
+ char *p = NULL;
if (!cmd && !prog) {
errno = EFAULT;
@@ -908,7 +910,9 @@ CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HAND
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
if (prog) {
- shell = prog;
+ if (!(p = dln_find_exe(prog, NULL))) {
+ shell = prog;
+ }
}
else {
int redir = -1;
@@ -938,15 +942,45 @@ CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HAND
cmd = tmp;
}
else {
- char *tmp = ALLOCA_N(char, len + 1);
- sprintf(tmp, "%.*s", len, cmd);
- cmd = tmp;
shell = NULL;
+ prog = cmd;
+ for (;;) {
+ if (!*prog) {
+ p = dln_find_exe(cmd, NULL);
+ break;
+ }
+ if (strchr(".:*?\"/\\", *prog)) {
+ if (cmd[len]) {
+ char *tmp = ALLOCA_N(char, len + 1);
+ memcpy(tmp, cmd, len);
+ tmp[len] = 0;
+ cmd = tmp;
+ }
+ break;
+ }
+ if (ISSPACE(*prog) || strchr("<>|", *prog)) {
+ len = prog - cmd;
+ p = ALLOCA_N(char, len + 1);
+ memcpy(p, cmd, len);
+ p[len] = 0;
+ p = dln_find_exe(p, NULL);
+ break;
+ }
+ prog++;
+ }
+ }
+ }
+ if (p) {
+ shell = p;
+ while (*p) {
+ if ((unsigned char)*p == '/')
+ *p = '\\';
+ p = CharNext(p);
}
}
RUBY_CRITICAL({
- fRet = CreateProcess(shell, cmd, psa, psa,
+ fRet = CreateProcess(shell, (char *)cmd, psa, psa,
psa->bInheritHandle, dwCreationFlags, NULL, NULL,
&aStartupInfo, &aProcessInformation);
errno = map_errno(GetLastError());