Skip to content

Commit b2cb97b

Browse files
committed
Convert 'mode' member of proc_open_descriptor_item to 'is_pipe'
This field has 3 possible values: DESC_FILE, DESC_PIPE, and DESC_REDIRECT, but the code only cares about whether the value is DESC_PIPE or not. Therefore, make the code simpler and clearer by converting the field to a boolean called 'is_pipe'.
1 parent 6102a54 commit b2cb97b

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

ext/standard/proc_open.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,10 @@ static inline HANDLE dup_fd_as_handle(int fd)
385385
# define close_descriptor(fd) close(fd)
386386
#endif
387387

388-
/* possible values of php_proc_open_descriptor_item.mode */
389-
#define DESC_PIPE 1
390-
#define DESC_FILE 2
391-
#define DESC_REDIRECT 3
392-
393388
struct php_proc_open_descriptor_item {
394389
int index; /* desired FD number in child process */
390+
int is_pipe;
395391
php_file_descriptor_t parentend, childend; /* FDs for pipes in parent/child */
396-
int mode; /* mode for proc_open code */
397392
int mode_flags; /* mode flags for opening FDs */
398393
};
399394
/* }}} */
@@ -562,7 +557,6 @@ static int set_proc_descriptor_to_blackhole(struct php_proc_open_descriptor_item
562557
return FAILURE;
563558
}
564559
#endif
565-
desc->mode = DESC_FILE;
566560
return SUCCESS;
567561
}
568562

@@ -575,7 +569,7 @@ static int set_proc_descriptor_to_pipe(struct php_proc_open_descriptor_item *des
575569
return FAILURE;
576570
}
577571

578-
desc->mode = DESC_PIPE;
572+
desc->is_pipe = 1;
579573

580574
if (strncmp(Z_STRVAL_P(zmode), "w", 1) != 0) {
581575
desc->parentend = newpipe[1];
@@ -614,8 +608,6 @@ static int set_proc_descriptor_to_file(struct php_proc_open_descriptor_item *des
614608
return FAILURE;
615609
}
616610

617-
desc->mode = DESC_FILE;
618-
619611
#ifdef PHP_WIN32
620612
desc->childend = dup_fd_as_handle((int)fd);
621613
_close((int)fd);
@@ -800,8 +792,6 @@ PHP_FUNCTION(proc_open)
800792
goto exit_fail;
801793
}
802794
#endif
803-
descriptors[ndesc].mode = DESC_FILE;
804-
805795
} else if (Z_TYPE_P(descitem) != IS_ARRAY) {
806796
zend_argument_value_error(2, "must only contain arrays and File-Handles");
807797
goto exit_fail;
@@ -914,7 +904,6 @@ PHP_FUNCTION(proc_open)
914904
goto exit_fail;
915905
}
916906
#endif
917-
descriptors[ndesc].mode = DESC_REDIRECT;
918907
} else if (strcmp(Z_STRVAL_P(ztype), "null") == 0) {
919908
if (set_proc_descriptor_to_blackhole(&descriptors[ndesc]) == FAILURE) {
920909
goto exit_fail;
@@ -937,7 +926,7 @@ PHP_FUNCTION(proc_open)
937926
goto exit_fail;
938927
}
939928
}
940-
descriptors[ndesc].mode = DESC_PIPE;
929+
descriptors[ndesc].is_pipe = 1;
941930
descriptors[ndesc].childend = dup(slave_pty);
942931
descriptors[ndesc].parentend = dup(dev_ptmx);
943932
descriptors[ndesc].mode_flags = O_RDWR;
@@ -1061,7 +1050,7 @@ PHP_FUNCTION(proc_open)
10611050
* dup new descriptors into required descriptors and close the original
10621051
* cruft */
10631052
for (i = 0; i < ndesc; i++) {
1064-
if (descriptors[i].mode == DESC_PIPE) {
1053+
if (descriptors[i].is_pipe) {
10651054
close(descriptors[i].parentend);
10661055
}
10671056
if (dup2(descriptors[i].childend, descriptors[i].index) < 0) {
@@ -1135,7 +1124,7 @@ PHP_FUNCTION(proc_open)
11351124

11361125
close_descriptor(descriptors[i].childend);
11371126

1138-
if (descriptors[i].mode == DESC_PIPE) {
1127+
if (descriptors[i].is_pipe) {
11391128
switch(descriptors[i].mode_flags) {
11401129
#ifdef PHP_WIN32
11411130
case O_WRONLY|O_BINARY:

0 commit comments

Comments
 (0)