diff options
author | khan <khan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-01-04 21:09:51 +0000 |
---|---|---|
committer | khan <khan@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-01-04 21:09:51 +0000 |
commit | b99e5aef5eb295200bb2c5fc1b0d2ea1a0649018 (patch) | |
tree | dd3b6ab2caedfc2fd72ca7e639185275c886e642 /libiberty/pexecute.c | |
parent | a36bcaf4545b51ca9785d41f6a95296c0a839316 (diff) | |
download | gcc-b99e5aef5eb295200bb2c5fc1b0d2ea1a0649018.tar.gz |
2000-01-04 Mumit Khan <khan@xraylith.wisc.edu>
* pexecute.c: Conditionally include string.h.
(fix_argv): Handle embedded whitespace in args for Mingw32.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@31214 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/pexecute.c')
-rw-r--r-- | libiberty/pexecute.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/libiberty/pexecute.c b/libiberty/pexecute.c index dffd04f5a91..5003f1fe4d5 100644 --- a/libiberty/pexecute.c +++ b/libiberty/pexecute.c @@ -1,6 +1,6 @@ /* Utilities to execute a program in a subprocess (possibly linked by pipes with other subprocesses), and wait for it. - Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. + Copyright (C) 1996-2000 Free Software Foundation, Inc. This file is part of the libiberty library. Libiberty is free software; you can redistribute it and/or @@ -29,6 +29,9 @@ Boston, MA 02111-1307, USA. */ #include <stdio.h> #include <errno.h> +#ifdef HAVE_STRING_H +#include <string.h> +#endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif @@ -279,6 +282,45 @@ fix_argv (argvec) argvec[i] = temp; } + for (i = 0; argvec[i] != 0; i++) + { + if (strpbrk (argvec[i], " \t")) + { + int len, trailing_backslash; + char *temp; + + len = strlen (argvec[i]); + trailing_backslash = 0; + + /* There is an added complication when an arg with embedded white + space ends in a backslash (such as in the case of -iprefix arg + passed to cpp). The resulting quoted strings gets misinterpreted + by the command interpreter -- it thinks that the ending quote + is escaped by the trailing backslash and things get confused. + We handle this case by escaping the trailing backslash, provided + it was not escaped in the first place. */ + if (len > 1 + && argvec[i][len-1] == '\\' + && argvec[i][len-2] != '\\') + { + trailing_backslash = 1; + ++len; /* to escape the final backslash. */ + } + + len += 2; /* and for the enclosing quotes. */ + + temp = xmalloc (len + 1); + temp[0] = '"'; + strcpy (temp + 1, argvec[i]); + if (trailing_backslash) + temp[len-2] = '\\'; + temp[len-1] = '"'; + temp[len] = '\0'; + + argvec[i] = temp; + } + } + return (const char * const *) argvec; } #endif /* __CYGWIN__ */ |