From ced1f9aa91ee36857fec9664c9ccd86ba2310821 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 18 Aug 2026 04:47:02 +0900 Subject: 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. --- crates/shirabe/src/util/platform.rs | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'crates/shirabe/src/util/platform.rs') 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 -- cgit v1.3.1-4-g156e