Changeset 946 for trunk/src/binutils/libiberty/pex-os2.c
- Timestamp:
- Jan 11, 2004, 5:40:14 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/binutils/libiberty/pex-os2.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r945 r946 22 22 #include "pex-common.h" 23 23 24 #include <stdio.h> 25 #include <errno.h> 26 #ifdef NEED_DECLARATION_ERRNO 27 extern int errno; 28 #endif 29 #ifdef HAVE_STRING_H 30 #include <string.h> 31 #endif 24 32 #ifdef HAVE_UNISTD_H 25 33 #include <unistd.h> … … 31 39 #include <sys/wait.h> 32 40 #endif 41 42 #ifndef HAVE_WAITPID 43 #define waitpid(pid, status, flags) wait(status) 44 #endif 45 33 46 #include <process.h> 47 #define INCL_BASE 48 #include <os2.h> 34 49 35 50 int … … 42 57 int flags; 43 58 { 59 static int last_pipe_input = STDIN_FILE_NO; 44 60 int pid; 61 int pdes[2], org_stdin, org_stdout; 62 int input_desc = last_pipe_input; 63 int output_desc = STDOUT_FILE_NO; 64 #ifdef __OS2__ 65 #define pipes_supported 1 66 #else 67 int pipes_supported = _osmode != DOS_MODE || (_emx_env & 0x1000); 45 68 46 if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE) 47 abort (); 48 pid = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_WAIT, program, argv); 69 if (!pipes_supported && (flags & PEXECUTE_ONE) != PEXECUTE_ONE) 70 { 71 static char *errtpl = "%s: exec %s (pipes not supported)"; 72 *errmsg_fmt = (char *) xmalloc (strlen(errtpl) + \ 73 strlen(this_pname) + strlen(program)); 74 sprintf (*errmsg_fmt, errtpl, this_pname, program); 75 *errmsg_arg = NULL; 76 return -1; 77 } 78 #endif 79 80 /* If this isn't the last process, make a pipe for its output, 81 and record it as waiting to be the input to the next process. */ 82 if (!(flags & PEXECUTE_LAST)) 83 { 84 if (pipe (pdes) < 0) 85 { 86 static char *errtpl = "%s: pipe to/from %s"; 87 *errmsg_fmt = (char *) xmalloc (strlen(errtpl) + \ 88 strlen(this_pname) + strlen(program)); 89 sprintf (*errmsg_fmt, errtpl, this_pname, program); 90 *errmsg_arg = NULL; 91 return -1; 92 } 93 output_desc = pdes[WRITE_PORT]; 94 last_pipe_input = pdes[READ_PORT]; 95 } 96 else 97 last_pipe_input = STDIN_FILE_NO; 98 if (pipes_supported && input_desc != STDIN_FILE_NO) 99 { 100 org_stdin = dup (STDIN_FILE_NO); 101 dup2 (input_desc, STDIN_FILE_NO); 102 close (input_desc); 103 } 104 if (pipes_supported && output_desc != STDOUT_FILE_NO) 105 { 106 org_stdout = dup (STDOUT_FILE_NO); 107 dup2 (output_desc, STDOUT_FILE_NO); 108 close (output_desc); 109 } 110 pid = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_NOWAIT, program, argv); 111 if (pipes_supported && input_desc != STDIN_FILE_NO) 112 { 113 dup2 (org_stdin, STDIN_FILE_NO); 114 close (org_stdin); 115 } 116 if (pipes_supported && output_desc != STDOUT_FILE_NO) 117 { 118 dup2 (org_stdout, STDOUT_FILE_NO); 119 close (org_stdout); 120 } 49 121 if (pid == -1) 50 122 { 51 *errmsg_fmt = install_error_msg; 52 *errmsg_arg = program; 53 return -1; 123 static char *errtpl = "%s: error executing %s"; 124 *errmsg_fmt = (char *) xmalloc (strlen(errtpl) + \ 125 strlen(this_pname) + strlen(program)); 126 sprintf (*errmsg_fmt, errtpl, this_pname, program); 127 *errmsg_arg = NULL; 54 128 } 55 129 return pid; 56 130 } 131 57 132 58 133 int … … 64 139 /* ??? Here's an opportunity to canonicalize the values in STATUS. 65 140 Needed? */ 66 int pid = wait (status); 67 return pid; 141 int rc; 142 do 143 rc = waitpid (pid, status, flags); 144 while (rc < 0 && errno == EINTR); 145 return rc; 68 146 } 69 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.