Skip to content

Commit c56fa33

Browse files
committed
* 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
1 parent 9247eb1 commit c56fa33

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Mon Nov 29 13:57:38 2004 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* win32/win32.c (CreateChild): search executable file if no program
4+
name given. (backported from CVS HEAD)
5+
16
Mon Nov 29 13:37:54 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
27

38
* io.c (fptr_finalize): must not use FILE after fclose().

win32/win32.c

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -852,15 +852,17 @@ char **argv;
852852
}
853853

854854
static struct ChildRecord *
855-
CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HANDLE hOutput, HANDLE hError)
855+
CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
856+
HANDLE hInput, HANDLE hOutput, HANDLE hError)
856857
{
857858
BOOL fRet;
858859
DWORD dwCreationFlags;
859860
STARTUPINFO aStartupInfo;
860861
PROCESS_INFORMATION aProcessInformation;
861862
SECURITY_ATTRIBUTES sa;
862-
char *shell;
863+
const char *shell;
863864
struct ChildRecord *child;
865+
char *p = NULL;
864866

865867
if (!cmd && !prog) {
866868
errno = EFAULT;
@@ -908,7 +910,9 @@ CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HAND
908910
dwCreationFlags = (NORMAL_PRIORITY_CLASS);
909911

910912
if (prog) {
911-
shell = prog;
913+
if (!(p = dln_find_exe(prog, NULL))) {
914+
shell = prog;
915+
}
912916
}
913917
else {
914918
int redir = -1;
@@ -938,15 +942,45 @@ CreateChild(char *cmd, char *prog, SECURITY_ATTRIBUTES *psa, HANDLE hInput, HAND
938942
cmd = tmp;
939943
}
940944
else {
941-
char *tmp = ALLOCA_N(char, len + 1);
942-
sprintf(tmp, "%.*s", len, cmd);
943-
cmd = tmp;
944945
shell = NULL;
946+
prog = cmd;
947+
for (;;) {
948+
if (!*prog) {
949+
p = dln_find_exe(cmd, NULL);
950+
break;
951+
}
952+
if (strchr(".:*?\"/\\", *prog)) {
953+
if (cmd[len]) {
954+
char *tmp = ALLOCA_N(char, len + 1);
955+
memcpy(tmp, cmd, len);
956+
tmp[len] = 0;
957+
cmd = tmp;
958+
}
959+
break;
960+
}
961+
if (ISSPACE(*prog) || strchr("<>|", *prog)) {
962+
len = prog - cmd;
963+
p = ALLOCA_N(char, len + 1);
964+
memcpy(p, cmd, len);
965+
p[len] = 0;
966+
p = dln_find_exe(p, NULL);
967+
break;
968+
}
969+
prog++;
970+
}
971+
}
972+
}
973+
if (p) {
974+
shell = p;
975+
while (*p) {
976+
if ((unsigned char)*p == '/')
977+
*p = '\\';
978+
p = CharNext(p);
945979
}
946980
}
947981

948982
RUBY_CRITICAL({
949-
fRet = CreateProcess(shell, cmd, psa, psa,
983+
fRet = CreateProcess(shell, (char *)cmd, psa, psa,
950984
psa->bInheritHandle, dwCreationFlags, NULL, NULL,
951985
&aStartupInfo, &aProcessInformation);
952986
errno = map_errno(GetLastError());

0 commit comments

Comments
 (0)