diff options
author | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-01-17 21:30:39 +0000 |
---|---|---|
committer | law <law@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-01-17 21:30:39 +0000 |
commit | 113f026687f3eca824ba7d87ad6ceaf27d4f463a (patch) | |
tree | 3fb1bcc713bf0b50a9443986aa474ff823b51ca8 /libiberty/pexecute.c | |
parent | 3fd975cfea9517665009a0b1d474c2d8e7de3fff (diff) | |
download | gcc-113f026687f3eca824ba7d87ad6ceaf27d4f463a.tar.gz |
Add mingw32 support.
* pexecute.c (pexecute): New function for mingw32. Supports pipes.
(pwait): New function for mingw32.
* config.table (i[3456]86-*-mingw32*): Support for i386-mingw32.
* config/mt-mingw32: New file.
* xmalloc.c (first_break): Not used for mingw32.
(xmalloc_set_program_name): Don't use sbrk on mingw32.
(xmalloc): Likewise.
(xrealloc): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@17395 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/pexecute.c')
-rw-r--r-- | libiberty/pexecute.c | 149 |
1 files changed, 142 insertions, 7 deletions
diff --git a/libiberty/pexecute.c b/libiberty/pexecute.c index b8594eb0954..fbbea409147 100644 --- a/libiberty/pexecute.c +++ b/libiberty/pexecute.c @@ -223,14 +223,50 @@ pwait (pid, status, flags) #if defined (_WIN32) #include <process.h> -extern int _spawnv (); -extern int _spawnvp (); #ifdef __CYGWIN32__ #define fix_argv(argvec) (argvec) -#else +extern int _spawnv (); +extern int _spawnvp (); + +int +pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) + const char *program; + char * const *argv; + const char *this_pname; + const char *temp_base; + char **errmsg_fmt, **errmsg_arg; + int flags; +{ + int pid; + + if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE) + abort (); + pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv) + (_P_NOWAIT, program, fix_argv(argv)); + if (pid == -1) + { + *errmsg_fmt = install_error_msg; + *errmsg_arg = program; + return -1; + } + return pid; +} + +int +pwait (pid, status, flags) + int pid; + int *status; + int flags; +{ + /* ??? Here's an opportunity to canonicalize the values in STATUS. + Needed? */ + return cwait (status, pid, WAIT_CHILD); +} + +#else /* ! __CYGWIN32__ */ /* This is a kludge to get around the Microsoft C spawn functions' propensity to remove the outermost set of double quotes from all arguments. */ @@ -269,8 +305,24 @@ fix_argv (argvec) return (const char * const *) argvec; } -#endif /* ! defined (__CYGWIN32__) */ +#include <io.h> +#include <fcntl.h> +#include <signal.h> + +/* mingw32 headers may not define the following. */ + +#ifndef _P_WAIT +# define _P_WAIT 0 +# define _P_NOWAIT 1 +# define _P_OVERLAY 2 +# define _P_NOWAITO 3 +# define _P_DETACH 4 + +# define WAIT_CHILD 0 +# define WAIT_GRANDCHILD 1 +#endif +/* Win32 supports pipes */ int pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) const char *program; @@ -281,31 +333,114 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) int flags; { int pid; + int pdes[2], org_stdin, org_stdout; + int input_desc, output_desc; + int retries, sleep_interval; + + /* Pipe waiting from last process, to be used as input for the next one. + Value is STDIN_FILE_NO if no pipe is waiting + (i.e. the next command is the first of a group). */ + static int last_pipe_input; + + /* If this is the first process, initialize. */ + if (flags & PEXECUTE_FIRST) + last_pipe_input = STDIN_FILE_NO; + + input_desc = last_pipe_input; + + /* If this isn't the last process, make a pipe for its output, + and record it as waiting to be the input to the next process. */ + if (! (flags & PEXECUTE_LAST)) + { + if (_pipe (pdes, 256, O_BINARY) < 0) + { + *errmsg_fmt = "pipe"; + *errmsg_arg = NULL; + return -1; + } + output_desc = pdes[WRITE_PORT]; + last_pipe_input = pdes[READ_PORT]; + } + else + { + /* Last process. */ + output_desc = STDOUT_FILE_NO; + last_pipe_input = STDIN_FILE_NO; + } + + if (input_desc != STDIN_FILE_NO) + { + org_stdin = dup (STDIN_FILE_NO); + dup2 (input_desc, STDIN_FILE_NO); + close (input_desc); + } + + if (output_desc != STDOUT_FILE_NO) + { + org_stdout = dup (STDOUT_FILE_NO); + dup2 (output_desc, STDOUT_FILE_NO); + close (output_desc); + } - if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE) - abort (); pid = (flags & PEXECUTE_SEARCH ? _spawnvp : _spawnv) (_P_NOWAIT, program, fix_argv(argv)); + + if (input_desc != STDIN_FILE_NO) + { + dup2 (org_stdin, STDIN_FILE_NO); + close (org_stdin); + } + + if (output_desc != STDOUT_FILE_NO) + { + dup2 (org_stdout, STDOUT_FILE_NO); + close (org_stdout); + } + if (pid == -1) { *errmsg_fmt = install_error_msg; *errmsg_arg = program; return -1; } + return pid; } +/* MS CRTDLL doesn't return enough information in status to decide if the + child exited due to a signal or not, rather it simply returns an + integer with the exit code of the child; eg., if the child exited with + an abort() call and didn't have a handler for SIGABRT, it simply returns + with status = 3. We fix the status code to conform to the usual WIF* + macros. Note that WIFSIGNALED will never be true under CRTDLL. */ + int pwait (pid, status, flags) int pid; int *status; int flags; { + int termstat; + + pid = _cwait (&termstat, pid, WAIT_CHILD); + /* ??? Here's an opportunity to canonicalize the values in STATUS. Needed? */ - return _cwait (status, pid, WAIT_CHILD); + + /* cwait returns the child process exit code in termstat. + A value of 3 indicates that the child caught a signal, but not + which one. Since only SIGABRT, SIGFPE and SIGINT do anything, we + report SIGABRT. */ + if (termstat == 3) + *status = SIGABRT; + else + *status = (((termstat) & 0xff) << 8); + + return pid; } +#endif /* ! defined (__CYGWIN32__) */ + #endif /* _WIN32 */ #ifdef OS2 |