diff --git a/Cargo.toml b/Cargo.toml index 4988fc7..90f1c9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,13 +15,15 @@ keywords = ["which", "which-rs", "unix", "command"] [dependencies] either = "1.9.0" regex = { version = "1.10.2", optional = true } -rustix = { version = "0.38.30", default-features = false, features = ["fs", "std"] } [target.'cfg(any(windows, unix, target_os = "redox"))'.dependencies] home = "0.5.9" +[target.'cfg(any(unix, target_os = "wasi", target_os = "redox"))'.dependencies] +rustix = { version = "0.38.30", default-features = false, features = ["fs", "std"] } + [target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.52", features = ["Win32_Storage_FileSystem", "Win32_Foundation"] } +winsafe = { version = "0.0.19", features = ["kernel"] } once_cell = "1" [dev-dependencies] diff --git a/src/checker.rs b/src/checker.rs index ec1485e..9668443 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -11,7 +11,7 @@ impl ExecutableChecker { } impl Checker for ExecutableChecker { - #[cfg(any(unix, target_os = "wasi"))] + #[cfg(any(unix, target_os = "wasi", target_os = "redox"))] fn is_valid(&self, path: &Path) -> bool { use rustix::fs as rfs; rfs::access(path, rfs::Access::EXEC_OK).is_ok() @@ -53,18 +53,7 @@ impl Checker for ExistedChecker { #[cfg(target_os = "windows")] fn matches_arch(path: &Path) -> bool { - use std::os::windows::prelude::OsStrExt; - - let os_str = path - .as_os_str() - .encode_wide() - .chain(std::iter::once(0)) - .collect::>(); - let mut out = 0; - let is_executable = unsafe { - windows_sys::Win32::Storage::FileSystem::GetBinaryTypeW(os_str.as_ptr(), &mut out) - }; - is_executable != 0 + winsafe::GetBinaryType(&path.display().to_string()).is_ok() } pub struct CompositeChecker { diff --git a/src/lib.rs b/src/lib.rs index c8f0be8..8490cb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,8 @@ //! //! ``` +#![forbid(unsafe_code)] + mod checker; mod error; mod finder;