projects
/
ghc-hetmet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix the link to the ghc docs in libraries/prologue.txt
[ghc-hetmet.git]
/
includes
/
shell-tools.c
diff --git
a/includes/shell-tools.c
b/includes/shell-tools.c
index
29b2e2d
..
82c22d3
100644
(file)
--- a/
includes/shell-tools.c
+++ b/
includes/shell-tools.c
@@
-57,9
+57,10
@@
int run(char *this, char *program, int argc, char** argv) {
/* Compute length of the flattened 'argv', including spaces! */
cmdline_len = 0;
/* Compute length of the flattened 'argv', including spaces! */
cmdline_len = 0;
- for(i = 1; i < argc; i++) {
+ for(i = 0; i < argc; i++) {
/* Note: play it safe and quote all argv strings */
/* Note: play it safe and quote all argv strings */
- cmdline_len += 1 + strlen(argv[i]) + 2;
+ /* In the worst case we have to escape every character with a \ */
+ cmdline_len += 1 + 2 * strlen(argv[i]) + 2;
}
new_cmdline = (char*)malloc(sizeof(char) * (cmdline_len + 1));
if (!new_cmdline) {
}
new_cmdline = (char*)malloc(sizeof(char) * (cmdline_len + 1));
if (!new_cmdline) {
@@
-68,16
+69,21
@@
int run(char *this, char *program, int argc, char** argv) {
}
ptr = new_cmdline;
}
ptr = new_cmdline;
- for(i = 1; i < argc; i++) {
+ for(i = 0; i < argc; i++) {
*ptr++ = ' ';
*ptr++ = '"';
src = argv[i];
while(*src) {
*ptr++ = ' ';
*ptr++ = '"';
src = argv[i];
while(*src) {
+ /* Escape any \ and " characters */
+ if ((*src == '\\') || (*src == '"')) {
+ *ptr++ = '\\';
+ }
*ptr++ = *src++;
}
*ptr++ = '"';
}
*ptr = '\0';
*ptr++ = *src++;
}
*ptr++ = '"';
}
*ptr = '\0';
+ new_cmdline = new_cmdline + 1; /* Skip the leading space */
/* Note: Used to use _spawnv(_P_WAIT, ...) here, but it suffered
from the parent intercepting console events such as Ctrl-C,
/* Note: Used to use _spawnv(_P_WAIT, ...) here, but it suffered
from the parent intercepting console events such as Ctrl-C,