Skip to content

Commit fe45722

Browse files
committed
Introduce init_startup_info helper in proc_open.c
1 parent 151a915 commit fe45722

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

ext/standard/proc_open.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,32 @@ static void set_option(zval *other_options, char *option_name, int *option_bool)
481481
}
482482
}
483483
}
484+
485+
static void init_startup_info(STARTUPINFOW *si, struct php_proc_open_descriptor_item *descriptors, int ndesc)
486+
{
487+
memset(si, 0, sizeof(STARTUPINFOW));
488+
si->cb = sizeof(STARTUPINFOW);
489+
si->dwFlags = STARTF_USESTDHANDLES;
490+
491+
si->hStdInput = GetStdHandle(STD_INPUT_HANDLE);
492+
si->hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
493+
si->hStdError = GetStdHandle(STD_ERROR_HANDLE);
494+
495+
/* redirect stdin/stdout/stderr if requested */
496+
for (int i = 0; i < ndesc; i++) {
497+
switch(descriptors[i].index) {
498+
case 0:
499+
si->hStdInput = descriptors[i].childend;
500+
break;
501+
case 1:
502+
si->hStdOutput = descriptors[i].childend;
503+
break;
504+
case 2:
505+
si->hStdError = descriptors[i].childend;
506+
break;
507+
}
508+
}
509+
}
484510
#endif
485511

486512
static struct php_proc_open_descriptor_item* alloc_descriptor_array(zval *descriptorspec)
@@ -897,29 +923,7 @@ PHP_FUNCTION(proc_open)
897923
goto exit_fail;
898924
}
899925

900-
memset(&si, 0, sizeof(si));
901-
si.cb = sizeof(si);
902-
si.dwFlags = STARTF_USESTDHANDLES;
903-
904-
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
905-
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
906-
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
907-
908-
/* redirect stdin/stdout/stderr if requested */
909-
for (i = 0; i < ndesc; i++) {
910-
switch(descriptors[i].index) {
911-
case 0:
912-
si.hStdInput = descriptors[i].childend;
913-
break;
914-
case 1:
915-
si.hStdOutput = descriptors[i].childend;
916-
break;
917-
case 2:
918-
si.hStdError = descriptors[i].childend;
919-
break;
920-
}
921-
}
922-
926+
init_startup_info(&si, descriptors, ndesc);
923927

924928
memset(&pi, 0, sizeof(pi));
925929

0 commit comments

Comments
 (0)