@@ -622,6 +622,25 @@ static int set_proc_descriptor_to_file(struct php_proc_open_descriptor_item *des
622
622
return SUCCESS ;
623
623
}
624
624
625
+ static int dup_proc_descriptor (php_file_descriptor_t from , php_file_descriptor_t * to , zend_ulong nindex )
626
+ {
627
+ #ifdef PHP_WIN32
628
+ * to = dup_handle (from , TRUE, FALSE);
629
+ if (* to == NULL ) {
630
+ php_error_docref (NULL , E_WARNING , "Failed to dup() for descriptor " ZEND_LONG_FMT , nindex );
631
+ return FAILURE ;
632
+ }
633
+ #else
634
+ * to = dup (from );
635
+ if (* to < 0 ) {
636
+ php_error_docref (NULL , E_WARNING ,
637
+ "Failed to dup() for descriptor " ZEND_LONG_FMT " - %s" , nindex , strerror (errno ));
638
+ return FAILURE ;
639
+ }
640
+ #endif
641
+ return SUCCESS ;
642
+ }
643
+
625
644
static int close_parent_ends_of_pipes_in_child (struct php_proc_open_descriptor_item * descriptors , int ndesc )
626
645
{
627
646
/* we are running in child process
@@ -909,22 +928,9 @@ PHP_FUNCTION(proc_open)
909
928
#endif
910
929
}
911
930
912
- #ifdef PHP_WIN32
913
- descriptors [ndesc ].childend = dup_handle (childend , TRUE, FALSE);
914
- if (descriptors [ndesc ].childend == NULL ) {
915
- php_error_docref (NULL , E_WARNING ,
916
- "Failed to dup() for descriptor " ZEND_LONG_FMT , nindex );
931
+ if (dup_proc_descriptor (childend , & descriptors [ndesc ].childend , nindex ) == FAILURE ) {
917
932
goto exit_fail ;
918
933
}
919
- #else
920
- descriptors [ndesc ].childend = dup (childend );
921
- if (descriptors [ndesc ].childend < 0 ) {
922
- php_error_docref (NULL , E_WARNING ,
923
- "Failed to dup() for descriptor " ZEND_LONG_FMT " - %s" ,
924
- nindex , strerror (errno ));
925
- goto exit_fail ;
926
- }
927
- #endif
928
934
} else if (strcmp (Z_STRVAL_P (ztype ), "null" ) == 0 ) {
929
935
if (set_proc_descriptor_to_blackhole (& descriptors [ndesc ]) == FAILURE ) {
930
936
goto exit_fail ;
0 commit comments