@@ -623,6 +623,25 @@ static int set_proc_descriptor_to_file(struct php_proc_open_descriptor_item *des
623
623
return SUCCESS ;
624
624
}
625
625
626
+ static int dup_proc_descriptor (php_file_descriptor_t from , php_file_descriptor_t * to , zend_ulong nindex )
627
+ {
628
+ #ifdef PHP_WIN32
629
+ * to = dup_handle (from , TRUE, FALSE);
630
+ if (* to == NULL ) {
631
+ php_error_docref (NULL , E_WARNING , "Failed to dup() for descriptor " ZEND_LONG_FMT , nindex );
632
+ return FAILURE ;
633
+ }
634
+ #else
635
+ * to = dup (from );
636
+ if (* to < 0 ) {
637
+ php_error_docref (NULL , E_WARNING ,
638
+ "Failed to dup() for descriptor " ZEND_LONG_FMT " - %s" , nindex , strerror (errno ));
639
+ return FAILURE ;
640
+ }
641
+ #endif
642
+ return SUCCESS ;
643
+ }
644
+
626
645
static int close_parent_ends_of_pipes_in_child (struct php_proc_open_descriptor_item * descriptors , int ndesc )
627
646
{
628
647
/* 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