diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 8fc990b206a..a0b4ed39d50 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,8 @@ +2000-01-04 Mumit Khan + + * pexecute.c: Conditionally include string.h. + (fix_argv): Handle embedded whitespace in args for Mingw32. + 2000-01-04 Kaveh R. Ghazi * configure.in (ac_libiberty_warn_cflags): Turn on warnings if 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 #include +#ifdef HAVE_STRING_H +#include +#endif #ifdef HAVE_UNISTD_H #include #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__ */