streams: use RETURN_BOOL() when possible

This commit is contained in:
Gina Peter Banyard 2025-07-12 13:23:37 +01:00
parent b46c5e6186
commit cd13ba73e2

View file

@ -1362,11 +1362,7 @@ PHP_FUNCTION(stream_set_blocking)
Z_PARAM_BOOL(block) Z_PARAM_BOOL(block)
ZEND_PARSE_PARAMETERS_END(); ZEND_PARSE_PARAMETERS_END();
if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block, NULL) == -1) { RETURN_BOOL(-1 != php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block, NULL));
RETURN_FALSE;
}
RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -1407,11 +1403,7 @@ PHP_FUNCTION(stream_set_timeout)
} }
#endif #endif
if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &t)) { RETURN_BOOL(PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &t));
RETURN_TRUE;
}
RETURN_FALSE;
} }
#endif /* HAVE_SYS_TIME_H || defined(PHP_WIN32) */ #endif /* HAVE_SYS_TIME_H || defined(PHP_WIN32) */
/* }}} */ /* }}} */
@ -1587,11 +1579,7 @@ PHP_FUNCTION(stream_is_local)
wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(zstream), NULL, 0); wrapper = php_stream_locate_url_wrapper(Z_STRVAL_P(zstream), NULL, 0);
} }
if (!wrapper) { RETURN_BOOL(wrapper && wrapper->is_url == 0);
RETURN_FALSE;
}
RETURN_BOOL(wrapper->is_url==0);
} }
/* }}} */ /* }}} */
@ -1604,11 +1592,7 @@ PHP_FUNCTION(stream_supports_lock)
PHP_Z_PARAM_STREAM(stream) PHP_Z_PARAM_STREAM(stream)
ZEND_PARSE_PARAMETERS_END(); ZEND_PARSE_PARAMETERS_END();
if (!php_stream_supports_lock(stream)) { RETURN_BOOL(php_stream_supports_lock(stream));
RETURN_FALSE;
}
RETURN_TRUE;
} }
/* {{{ Check if a stream is a TTY. */ /* {{{ Check if a stream is a TTY. */
@ -1635,15 +1619,13 @@ PHP_FUNCTION(stream_isatty)
#ifdef PHP_WIN32 #ifdef PHP_WIN32
/* Check if the Windows standard handle is redirected to file */ /* Check if the Windows standard handle is redirected to file */
RETVAL_BOOL(php_win32_console_fileno_is_console(fileno)); RETURN_BOOL(php_win32_console_fileno_is_console(fileno));
#elif defined(HAVE_UNISTD_H) #elif defined(HAVE_UNISTD_H)
/* Check if the file descriptor identifier is a terminal */ /* Check if the file descriptor identifier is a terminal */
RETVAL_BOOL(isatty(fileno)); RETURN_BOOL(isatty(fileno));
#else #else
{
zend_stat_t stat = {0}; zend_stat_t stat = {0};
RETVAL_BOOL(zend_fstat(fileno, &stat) == 0 && (stat.st_mode & /*S_IFMT*/0170000) == /*S_IFCHR*/0020000); RETURN_BOOL(zend_fstat(fileno, &stat) == 0 && (stat.st_mode & /*S_IFMT*/0170000) == /*S_IFCHR*/0020000);
}
#endif #endif
} }
@ -1689,21 +1671,10 @@ PHP_FUNCTION(sapi_windows_vt100_support)
if (enable_is_null) { if (enable_is_null) {
/* Check if the Windows standard handle has VT100 control codes enabled */ /* Check if the Windows standard handle has VT100 control codes enabled */
if (php_win32_console_fileno_has_vt100(fileno)) { RETURN_BOOL(php_win32_console_fileno_has_vt100(fileno));
RETURN_TRUE; } else {
}
else {
RETURN_FALSE;
}
}
else {
/* Enable/disable VT100 control codes support for the specified Windows standard handle */ /* Enable/disable VT100 control codes support for the specified Windows standard handle */
if (php_win32_console_fileno_set_vt100(fileno, enable ? TRUE : FALSE)) { RETURN_BOOL(php_win32_console_fileno_set_vt100(fileno, enable ? TRUE : FALSE));
RETURN_TRUE;
}
else {
RETURN_FALSE;
}
} }
} }
#endif #endif