Skip to content

Commit 8dbf742

Browse files
committed
Simplify code for handling streams in proc_open
1 parent fa49945 commit 8dbf742

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
@@ -812,6 +812,7 @@ PHP_FUNCTION(proc_open)
812812
/* should be a stream - try and dup the descriptor */
813813
php_stream *stream;
814814
php_socket_t fd;
815+
php_file_descriptor_t desc;
815816

816817
php_stream_from_zval(stream, descitem);
817818

@@ -820,18 +821,13 @@ PHP_FUNCTION(proc_open)
820821
}
821822

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

0 commit comments

Comments
 (0)