Skip to content

Commit 38c5596

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 11bdeb9 commit 38c5596

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
/* }}} */
@@ -561,7 +556,6 @@ static int set_proc_descriptor_to_blackhole(struct php_proc_open_descriptor_item
561556
return FAILURE;
562557
}
563558
#endif
564-
desc->mode = DESC_FILE;
565559
return SUCCESS;
566560
}
567561

@@ -574,7 +568,7 @@ static int set_proc_descriptor_to_pipe(struct php_proc_open_descriptor_item *des
574568
return FAILURE;
575569
}
576570

577-
desc->mode = DESC_PIPE;
571+
desc->is_pipe = 1;
578572

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

616-
desc->mode = DESC_FILE;
617-
618610
#ifdef PHP_WIN32
619611
desc->childend = dup_fd_as_handle((int)fd);
620612
_close((int)fd);
@@ -799,8 +791,6 @@ PHP_FUNCTION(proc_open)
799791
goto exit_fail;
800792
}
801793
#endif
802-
descriptors[ndesc].mode = DESC_FILE;
803-
804794
} else if (Z_TYPE_P(descitem) != IS_ARRAY) {
805795
zend_argument_value_error(2, "must only contain arrays and File-Handles");
806796
goto exit_fail;
@@ -913,7 +903,6 @@ PHP_FUNCTION(proc_open)
913903
goto exit_fail;
914904
}
915905
#endif
916-
descriptors[ndesc].mode = DESC_REDIRECT;
917906
} else if (strcmp(Z_STRVAL_P(ztype), "null") == 0) {
918907
if (set_proc_descriptor_to_blackhole(&descriptors[ndesc]) == FAILURE) {
919908
goto exit_fail;
@@ -936,7 +925,7 @@ PHP_FUNCTION(proc_open)
936925
goto exit_fail;
937926
}
938927
}
939-
descriptors[ndesc].mode = DESC_PIPE;
928+
descriptors[ndesc].is_pipe = 1;
940929
descriptors[ndesc].childend = dup(slave_pty);
941930
descriptors[ndesc].parentend = dup(dev_ptmx);
942931
descriptors[ndesc].mode_flags = O_RDWR;
@@ -1062,7 +1051,7 @@ PHP_FUNCTION(proc_open)
10621051
* dup new descriptors into required descriptors and close the original
10631052
* cruft */
10641053
for (i = 0; i < ndesc; i++) {
1065-
if (descriptors[i].mode == DESC_PIPE) {
1054+
if (descriptors[i].is_pipe) {
10661055
close(descriptors[i].parentend);
10671056
}
10681057
if (dup2(descriptors[i].childend, descriptors[i].index) < 0) {
@@ -1138,7 +1127,7 @@ PHP_FUNCTION(proc_open)
11381127

11391128
close_descriptor(descriptors[i].childend);
11401129

1141-
if (descriptors[i].mode == DESC_PIPE) {
1130+
if (descriptors[i].is_pipe) {
11421131
switch(descriptors[i].mode_flags) {
11431132
#ifdef PHP_WIN32
11441133
case O_WRONLY|O_BINARY:

0 commit comments

Comments
 (0)