Skip to content

Commit c9f042b

Browse files
committed
Simplify code for handling streams in proc_open
1 parent 0524fbe commit c9f042b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

ext/standard/proc_open.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ PHP_FUNCTION(proc_open)
814814
/* should be a stream - try and dup the descriptor */
815815
php_stream *stream;
816816
php_socket_t fd;
817+
php_file_descriptor_t desc;
817818

818819
php_stream_from_zval(stream, descitem);
819820

@@ -822,18 +823,13 @@ PHP_FUNCTION(proc_open)
822823
}
823824

824825
#ifdef PHP_WIN32
825-
descriptors[ndesc].childend = dup_fd_as_handle((int)fd);
826-
if (descriptors[ndesc].childend == NULL) {
827-
php_error_docref(NULL, E_WARNING, "Unable to dup File-Handle for descriptor %d", nindex);
828-
goto exit_fail;
829-
}
826+
desc = (HANDLE)_get_osfhandle(fd);
830827
#else
831-
descriptors[ndesc].childend = dup(fd);
832-
if (descriptors[ndesc].childend < 0) {
833-
php_error_docref(NULL, E_WARNING, "Unable to dup File-Handle for descriptor " ZEND_ULONG_FMT " - %s", nindex, strerror(errno));
828+
desc = fd;
829+
#endif
830+
if (dup_proc_descriptor(desc, &descriptors[ndesc].childend, nindex) == FAILURE) {
834831
goto exit_fail;
835832
}
836-
#endif
837833
} else if (Z_TYPE_P(descitem) != IS_ARRAY) {
838834
zend_argument_value_error(2, "must only contain arrays and File-Handles");
839835
goto exit_fail;

0 commit comments

Comments
 (0)