From 0c0a36a40386d288fe8d6d86efc2b178ef7eb465 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 22 Feb 2000 16:14:35 +0000 Subject: merge with libiberty from egcs 2000-02-22 --- libiberty/pexecute.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'libiberty/pexecute.c') diff --git a/libiberty/pexecute.c b/libiberty/pexecute.c index c644c98..56ddec7 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 @@ -52,10 +55,6 @@ Boston, MA 02111-1307, USA. */ #include "libiberty.h" -#if !defined (__CYGWIN__) && defined (__CYGWIN32__) -#define __CYGWIN__ 1 -#endif - /* stdin file number. */ #define STDIN_FILE_NO 0 @@ -160,6 +159,8 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) FILE *argfile; int i, el = flags & PEXECUTE_SEARCH ? 4 : 0; + if (temp_base == 0) + temp_base = choose_temp_base (); scmd = (char *) xmalloc (strlen (program) + strlen (temp_base) + 6 + el); rf = scmd + strlen(program) + 2 + el; sprintf (scmd, "%s%s @%s.gp", program, @@ -234,7 +235,7 @@ pwait (pid, status, flags) #endif /* MSDOS */ -#if defined (_WIN32) && ! defined (__UWIN__) +#if defined (_WIN32) && ! defined (_UWIN) #include @@ -281,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__ */ @@ -423,7 +463,7 @@ pwait (pid, status, flags) #endif /* __CYGWIN__ */ } -#endif /* _WIN32 && ! __UWIN__ */ +#endif /* _WIN32 && ! _UWIN */ #ifdef OS2 @@ -606,7 +646,7 @@ pfinish () /* include for Unix-like environments but not for Dos-like environments */ #if ! defined (__MSDOS__) && ! defined (OS2) && ! defined (MPW) \ - && ! (defined (_WIN32) && ! defined (__UWIN__)) + && ! (defined (_WIN32) && ! defined (_UWIN)) extern int execv (); extern int execvp (); @@ -735,4 +775,4 @@ pwait (pid, status, flags) return pid; } -#endif /* ! __MSDOS__ && ! OS2 && ! MPW && ! (_WIN32 && ! __UWIN__) */ +#endif /* ! __MSDOS__ && ! OS2 && ! MPW && ! (_WIN32 && ! _UWIN) */ -- cgit v1.1