summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-15 19:58:32 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-15 19:58:32 +0000
commit6c80040ef41db245fa442ad6e7e7b4d1215ce5d7 (patch)
tree3396ea719e907bd7d9d9aab8f12c35f7c7b4ef67 /win32/win32.c
parent467d6abc59180247311575c90885b225ea876e61 (diff)
* win32/win32.c (CreateChild): enclose command line except for
command.com which can not handle quotes. [ruby-talk:258939] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@12982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/win32/win32.c b/win32/win32.c
index b88c136467..cdb5b61bc9 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -528,7 +528,7 @@ SafeFree(char **vec, int vecc)
-e 'END{$cmds.sort.each{|n,f|puts " \"\\#{f.to_s(8)}\" #{n.dump} + 1,"}}'
98cmd ntcmd
*/
-static char *szInternalCmds[] = {
+static const char *const szInternalCmds[] = {
"\2" "assoc" + 1,
"\3" "break" + 1,
"\3" "call" + 1,
@@ -587,16 +587,22 @@ internal_match(const void *key, const void *elem)
}
static int
-isInternalCmd(const char *cmd, const char *interp)
+is_command_com(const char *interp)
{
- int i, nt = 1;
- char cmdname[9], *b = cmdname, c, **nm;
+ int i = strlen(interp) - 11;
- i = strlen(interp) - 11;
if ((i == 0 || i > 0 && isdirsep(interp[i-1])) &&
strcasecmp(interp+i, "command.com") == 0) {
- nt = 0;
+ return 1;
}
+ return 0;
+}
+
+static int
+is_internal_cmd(const char *cmd, int nt)
+{
+ char cmdname[9], *b = cmdname, c, **nm;
+
do {
if (!(c = *cmd++)) return 0;
} while (isspace(c));
@@ -964,6 +970,7 @@ CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
else {
int redir = -1;
int len = 0;
+ int nt;
while (ISSPACE(*cmd)) cmd++;
for (prog = cmd; *prog; prog = CharNext(prog)) {
if (ISSPACE(*prog)) {
@@ -982,10 +989,12 @@ CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
cmd = tmp;
}
else if ((shell = getenv("COMSPEC")) &&
- ((redir < 0 ? has_redirection(cmd) : redir) ||
- isInternalCmd(cmd, shell))) {
- char *tmp = ALLOCA_N(char, strlen(shell) + len + sizeof(" /c "));
- sprintf(tmp, "%s /c %.*s", shell, len, cmd);
+ (nt = !is_command_com(shell),
+ (redir < 0 ? has_redirection(cmd) : redir) ||
+ is_internal_cmd(cmd, nt))) {
+ char *tmp = ALLOCA_N(char, strlen(shell) + len + sizeof(" /c ")
+ + (nt ? 2 : 0));
+ sprintf(tmp, nt ? "%s /c \"%.*s\"" : "%s /c %.*s", shell, len, cmd);
cmd = tmp;
}
else {