Changeset 9 for trunk/src/gcc/libiberty/pexecute.c
- Timestamp:
- Apr 16, 2003, 4:03:38 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gcc/libiberty/pexecute.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r8 r9 82 82 (??? It's not clear that GCC passes this flag correctly). (@code{@var{flags} & 83 83 PEXECUTE_FIRST}) is nonzero for the first process in chain. 84 (@code{@var{flags} & PEXECUTE_ FIRST}) is nonzero for the last process84 (@code{@var{flags} & PEXECUTE_LAST}) is nonzero for the last process 85 85 in chain. The first/last flags could be simplified to only mark the 86 86 last of a chain of processes but that requires the caller to always … … 484 484 #ifdef OS2 485 485 486 /* ??? Does OS2 have process.h?*/486 /* This is for non-EMX OS/2 port (is it floating around anyway?) */ 487 487 extern int spawnv (); 488 488 extern int spawnvp (); … … 663 663 /* include for Unix-like environments but not for Dos-like environments */ 664 664 #if ! defined (__MSDOS__) && ! defined (OS2) && ! defined (MPW) \ 665 && ! (defined (_WIN32) && ! defined (_UWIN)) 665 && ! (defined (_WIN32) && ! defined (_UWIN)) && ! defined (__EMX__) 666 666 667 667 extern int execv (); … … 790 790 } 791 791 792 #endif /* ! __MSDOS__ && ! OS2 && ! MPW && ! (_WIN32 && ! _UWIN) */ 792 #endif /* ! __MSDOS__ && ! OS2 && ! MPW && ! (_WIN32 && ! _UWIN) && ! && ! __EMX__ */ 793 794 #ifdef __EMX__ 795 796 #undef abort 797 #include <process.h> 798 #include <stdlib.h> 799 #define INCL_DOSPROCESS 800 #include <os2.h> 801 802 int 803 pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) 804 const char *program; 805 char * const *argv; 806 const char *this_pname; 807 const char *temp_base; 808 char **errmsg_fmt, **errmsg_arg; 809 int flags; 810 { 811 static int last_pipe_input = STDIN_FILE_NO; 812 int pid; 813 int pdes[2], org_stdin, org_stdout; 814 int input_desc = last_pipe_input; 815 int output_desc = STDOUT_FILE_NO; 816 int pipes_supported = _osmode != DOS_MODE || (_emx_env & 0x1000); 817 818 /* Since the function can reside in a DLL, we should take care 819 environ to not be NULL. Unfortunately this involves os2.h :-( - A.Z. */ 820 if (!environ) 821 { 822 PTIB tib; 823 PPIB pib; 824 if (!DosGetInfoBlocks (&tib, &pib)) 825 { 826 int count = 1; 827 char *env = pib->pib_pchenv; 828 char **cur; 829 while (*env++) 830 if (!*env) 831 count++, env++; 832 cur = environ = malloc (sizeof (char *) * count); 833 env = pib->pib_pchenv; 834 *cur++ = env; 835 while (*env++) 836 if (!*env) 837 env++, *cur++ = env; 838 cur [-1] = NULL; 839 } 840 } 841 842 if (!pipes_supported && (flags & PEXECUTE_ONE) != PEXECUTE_ONE) 843 { 844 static char *errtpl = "%s: exec %s (pipes not supported)"; 845 *errmsg_fmt = (char *) xmalloc (strlen(errtpl) + \ 846 strlen(this_pname) + strlen(program)); 847 sprintf (*errmsg_fmt, errtpl, this_pname, program); 848 *errmsg_arg = NULL; 849 return -1; 850 } 851 /* If this isn't the last process, make a pipe for its output, 852 and record it as waiting to be the input to the next process. */ 853 if (!(flags & PEXECUTE_LAST)) 854 { 855 if (pipe (pdes) < 0) 856 { 857 static char *errtpl = "%s: pipe to/from %s"; 858 *errmsg_fmt = (char *) xmalloc (strlen(errtpl) + \ 859 strlen(this_pname) + strlen(program)); 860 sprintf (*errmsg_fmt, errtpl, this_pname, program); 861 *errmsg_arg = NULL; 862 return -1; 863 } 864 output_desc = pdes[WRITE_PORT]; 865 last_pipe_input = pdes[READ_PORT]; 866 } 867 else 868 last_pipe_input = STDIN_FILE_NO; 869 if (pipes_supported && input_desc != STDIN_FILE_NO) 870 { 871 org_stdin = dup (STDIN_FILE_NO); 872 dup2 (input_desc, STDIN_FILE_NO); 873 close (input_desc); 874 } 875 if (pipes_supported && output_desc != STDOUT_FILE_NO) 876 { 877 org_stdout = dup (STDOUT_FILE_NO); 878 dup2 (output_desc, STDOUT_FILE_NO); 879 close (output_desc); 880 } 881 pid = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_NOWAIT, program, argv); 882 if (pipes_supported && input_desc != STDIN_FILE_NO) 883 { 884 dup2 (org_stdin, STDIN_FILE_NO); 885 close (org_stdin); 886 } 887 if (pipes_supported && output_desc != STDOUT_FILE_NO) 888 { 889 dup2 (org_stdout, STDOUT_FILE_NO); 890 close (org_stdout); 891 } 892 if (pid == -1) 893 { 894 static char *errtpl = "%s: error executing %s"; 895 *errmsg_fmt = (char *) xmalloc (strlen(errtpl) + \ 896 strlen(this_pname) + strlen(program)); 897 sprintf (*errmsg_fmt, errtpl, this_pname, program); 898 *errmsg_arg = NULL; 899 } 900 return pid; 901 } 902 903 int 904 pwait (pid, status, flags) 905 int pid; 906 int *status; 907 int flags; 908 { 909 int rc; 910 do 911 rc = waitpid (pid, status, flags); 912 while (rc < 0 && errno == EINTR); 913 return rc; 914 } 915 916 #endif /* __EMX__ */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.