From c56fa330b24863f5e946caf7846a1a8b44674e48 Mon Sep 17 00:00:00 2001 From: usa Date: Mon, 29 Nov 2004 05:00:29 +0000 Subject: * 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 --- win32/win32.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'win32') 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()); -- cgit v1.2.3