Mercurial > hg > CbC > CbC_gcc
comparison libiberty/pex-win32.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
82 static pid_t pex_win32_exec_child (struct pex_obj *, int, const char *, | 82 static pid_t pex_win32_exec_child (struct pex_obj *, int, const char *, |
83 char * const *, char * const *, | 83 char * const *, char * const *, |
84 int, int, int, int, | 84 int, int, int, int, |
85 const char **, int *); | 85 const char **, int *); |
86 static int pex_win32_close (struct pex_obj *, int); | 86 static int pex_win32_close (struct pex_obj *, int); |
87 static int pex_win32_wait (struct pex_obj *, pid_t, int *, | 87 static pid_t pex_win32_wait (struct pex_obj *, pid_t, int *, |
88 struct pex_time *, int, const char **, int *); | 88 struct pex_time *, int, const char **, int *); |
89 static int pex_win32_pipe (struct pex_obj *, int *, int); | 89 static int pex_win32_pipe (struct pex_obj *, int *, int); |
90 static FILE *pex_win32_fdopenr (struct pex_obj *, int, int); | 90 static FILE *pex_win32_fdopenr (struct pex_obj *, int, int); |
91 static FILE *pex_win32_fdopenw (struct pex_obj *, int, int); | 91 static FILE *pex_win32_fdopenw (struct pex_obj *, int, int); |
92 | 92 |
703 *avhere = newex; | 703 *avhere = newex; |
704 pid = win32_spawn (newex, FALSE, argv, env, | 704 pid = win32_spawn (newex, FALSE, argv, env, |
705 dwCreationFlags, si, pi); | 705 dwCreationFlags, si, pi); |
706 if (executable1 != newex) | 706 if (executable1 != newex) |
707 free ((char *) newex); | 707 free ((char *) newex); |
708 if ((long) pid < 0) | 708 if (pid == (pid_t) -1) |
709 { | 709 { |
710 newex = msys_rootify (executable1); | 710 newex = msys_rootify (executable1); |
711 if (newex != executable1) | 711 if (newex != executable1) |
712 { | 712 { |
713 *avhere = newex; | 713 *avhere = newex; |
720 #endif | 720 #endif |
721 free (avhere); | 721 free (avhere); |
722 } | 722 } |
723 } | 723 } |
724 } | 724 } |
725 if ((long) pid < 0) | 725 if (pid == (pid_t) -1) |
726 errno = save_errno; | 726 errno = save_errno; |
727 return pid; | 727 return pid; |
728 } | 728 } |
729 | 729 |
730 /* Execute a child. */ | 730 /* Execute a child. */ |
744 HANDLE stderr_handle; | 744 HANDLE stderr_handle; |
745 DWORD dwCreationFlags; | 745 DWORD dwCreationFlags; |
746 OSVERSIONINFO version_info; | 746 OSVERSIONINFO version_info; |
747 STARTUPINFO si; | 747 STARTUPINFO si; |
748 PROCESS_INFORMATION pi; | 748 PROCESS_INFORMATION pi; |
749 int orig_out, orig_in, orig_err; | |
750 BOOL separate_stderr = !(flags & PEX_STDERR_TO_STDOUT); | |
751 | |
752 /* Ensure we have inheritable descriptors to pass to the child, and close the | |
753 original descriptors. */ | |
754 orig_in = in; | |
755 in = _dup (orig_in); | |
756 if (orig_in != STDIN_FILENO) | |
757 _close (orig_in); | |
758 | |
759 orig_out = out; | |
760 out = _dup (orig_out); | |
761 if (orig_out != STDOUT_FILENO) | |
762 _close (orig_out); | |
763 | |
764 if (separate_stderr) | |
765 { | |
766 orig_err = errdes; | |
767 errdes = _dup (orig_err); | |
768 if (orig_err != STDERR_FILENO) | |
769 _close (orig_err); | |
770 } | |
749 | 771 |
750 stdin_handle = INVALID_HANDLE_VALUE; | 772 stdin_handle = INVALID_HANDLE_VALUE; |
751 stdout_handle = INVALID_HANDLE_VALUE; | 773 stdout_handle = INVALID_HANDLE_VALUE; |
752 stderr_handle = INVALID_HANDLE_VALUE; | 774 stderr_handle = INVALID_HANDLE_VALUE; |
753 | 775 |
754 stdin_handle = (HANDLE) _get_osfhandle (in); | 776 stdin_handle = (HANDLE) _get_osfhandle (in); |
755 stdout_handle = (HANDLE) _get_osfhandle (out); | 777 stdout_handle = (HANDLE) _get_osfhandle (out); |
756 if (!(flags & PEX_STDERR_TO_STDOUT)) | 778 if (separate_stderr) |
757 stderr_handle = (HANDLE) _get_osfhandle (errdes); | 779 stderr_handle = (HANDLE) _get_osfhandle (errdes); |
758 else | 780 else |
759 stderr_handle = stdout_handle; | 781 stderr_handle = stdout_handle; |
760 | 782 |
761 /* Determine the version of Windows we are running on. */ | 783 /* Determine the version of Windows we are running on. */ |
820 { | 842 { |
821 *err = ENOENT; | 843 *err = ENOENT; |
822 *errmsg = "CreateProcess"; | 844 *errmsg = "CreateProcess"; |
823 } | 845 } |
824 | 846 |
825 /* Close the standard output and standard error handles in the | 847 /* Close the standard input, standard output and standard error handles |
826 parent. */ | 848 in the parent. */ |
827 if (out != STDOUT_FILENO) | 849 |
828 obj->funcs->close (obj, out); | 850 _close (in); |
829 if (errdes != STDERR_FILENO) | 851 _close (out); |
830 obj->funcs->close (obj, errdes); | 852 if (separate_stderr) |
853 _close (errdes); | |
831 | 854 |
832 return pid; | 855 return pid; |
833 } | 856 } |
834 | 857 |
835 /* Wait for a child process to complete. MS CRTDLL doesn't return | 858 /* Wait for a child process to complete. MS CRTDLL doesn't return |
838 code of the child; eg., if the child exited with an abort() call | 861 code of the child; eg., if the child exited with an abort() call |
839 and didn't have a handler for SIGABRT, it simply returns with | 862 and didn't have a handler for SIGABRT, it simply returns with |
840 status == 3. We fix the status code to conform to the usual WIF* | 863 status == 3. We fix the status code to conform to the usual WIF* |
841 macros. Note that WIFSIGNALED will never be true under CRTDLL. */ | 864 macros. Note that WIFSIGNALED will never be true under CRTDLL. */ |
842 | 865 |
843 static int | 866 static pid_t |
844 pex_win32_wait (struct pex_obj *obj ATTRIBUTE_UNUSED, pid_t pid, | 867 pex_win32_wait (struct pex_obj *obj ATTRIBUTE_UNUSED, pid_t pid, |
845 int *status, struct pex_time *time, int done ATTRIBUTE_UNUSED, | 868 int *status, struct pex_time *time, int done ATTRIBUTE_UNUSED, |
846 const char **errmsg, int *err) | 869 const char **errmsg, int *err) |
847 { | 870 { |
848 DWORD termstat; | 871 DWORD termstat; |
881 | 904 |
882 static int | 905 static int |
883 pex_win32_pipe (struct pex_obj *obj ATTRIBUTE_UNUSED, int *p, | 906 pex_win32_pipe (struct pex_obj *obj ATTRIBUTE_UNUSED, int *p, |
884 int binary) | 907 int binary) |
885 { | 908 { |
886 return _pipe (p, 256, binary ? _O_BINARY : _O_TEXT); | 909 return _pipe (p, 256, (binary ? _O_BINARY : _O_TEXT) | _O_NOINHERIT); |
887 } | 910 } |
888 | 911 |
889 /* Get a FILE pointer to read from a file descriptor. */ | 912 /* Get a FILE pointer to read from a file descriptor. */ |
890 | 913 |
891 static FILE * | 914 static FILE * |
892 pex_win32_fdopenr (struct pex_obj *obj ATTRIBUTE_UNUSED, int fd, | 915 pex_win32_fdopenr (struct pex_obj *obj ATTRIBUTE_UNUSED, int fd, |
893 int binary) | 916 int binary) |
894 { | 917 { |
918 HANDLE h = (HANDLE) _get_osfhandle (fd); | |
919 if (h == INVALID_HANDLE_VALUE) | |
920 return NULL; | |
921 if (! SetHandleInformation (h, HANDLE_FLAG_INHERIT, 0)) | |
922 return NULL; | |
895 return fdopen (fd, binary ? "rb" : "r"); | 923 return fdopen (fd, binary ? "rb" : "r"); |
896 } | 924 } |
897 | 925 |
898 static FILE * | 926 static FILE * |
899 pex_win32_fdopenw (struct pex_obj *obj ATTRIBUTE_UNUSED, int fd, | 927 pex_win32_fdopenw (struct pex_obj *obj ATTRIBUTE_UNUSED, int fd, |