diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-18 04:47:02 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-18 04:47:18 +0900 |
| commit | ced1f9aa91ee36857fec9664c9ccd86ba2310821 (patch) | |
| tree | 630ea3eb3b0e710403669de9ba6a78a421e182a8 /crates/shirabe/src/util/platform.rs | |
| parent | 6b7c6cb9a3d1cdf93f261238c1edbc70706a33c7 (diff) | |
| download | php-shirabe-ced1f9aa91ee36857fec9664c9ccd86ba2310821.tar.gz php-shirabe-ced1f9aa91ee36857fec9664c9ccd86ba2310821.tar.zst php-shirabe-ced1f9aa91ee36857fec9664c9ccd86ba2310821.zip | |
refactor(function-exists): drop checks for always-present capabilities
function_exists() returns false in PHP when a function is blocked by
disable_functions, when its extension is not compiled in, or when the
PHP version predates it. None of those apply to a native binary.
Diffstat (limited to 'crates/shirabe/src/util/platform.rs')
| -rw-r--r-- | crates/shirabe/src/util/platform.rs | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index ccee2953..c40f3ec5 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -4,8 +4,8 @@ use crate::util::ProcessExecutor; use crate::util::Silencer; use shirabe_php_shim::{ PHP_ENV, PHP_SERVER, PhpMixed, PhpResource, PregMatches, RuntimeException, defined, - file_exists, file_get_contents, fstat, function_exists, getcwd, getenv, ini_get, is_readable, - mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid, posix_isatty, + file_exists, file_get_contents, function_exists, getcwd, getenv, ini_get, is_readable, + mb_strlen, php_os_family, php_regex, posix_geteuid, posix_getpwuid, posix_getuid, preg_is_match, preg_replace_callback, putenv, putenv_clear, realpath, stream_isatty, stripos, strlen, strtoupper, substr, usleep, }; @@ -244,9 +244,7 @@ impl Platform { let mut use_mb_string = USE_MB_STRING.lock().unwrap(); if use_mb_string.is_none() { *use_mb_string = Some( - function_exists("mb_strlen") - && ini_get("mbstring.func_overload") - .is_some_and(|s| PhpMixed::String(s).to_bool()), + ini_get("mbstring.func_overload").is_some_and(|s| PhpMixed::String(s).to_bool()), ); } @@ -270,29 +268,7 @@ impl Platform { return true; } - // modern cross-platform function, includes the fstat - // fallback so if it is present we trust it - if function_exists("stream_isatty") { - return stream_isatty(fd); - } - - // only trusting this if it is positive, otherwise prefer fstat fallback - if function_exists("posix_isatty") && posix_isatty(fd.clone()) { - return true; - } - - let stat = Silencer::call(|| Ok(fstat(&fd))); - let stat = match stat { - Ok(s) => s, - Err(_) => return false, - }; - let stat = match stat { - Some(stat) => stat, - None => return false, - }; - - // Check if formatted mode is S_IFCHR - 0o020000 == (stat.mode & 0o170000) + stream_isatty(fd) } /// Whether the current command is for bash completion |
