diff --git a/Cargo.toml b/Cargo.toml index e05adb3..c7d1825 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,13 +13,14 @@ keywords = ["which", "which-rs", "unix", "command"] [dependencies] either = "1.6.1" -libc = "0.2.121" regex = { version = "1.5.5", optional = true } +rustix = { version = "0.38.10", default-features = false, features = ["fs", "std"] } [target.'cfg(windows)'.dependencies] once_cell = "1" [dev-dependencies] +libc = "0.2.147" tempfile = "3.3.0" [package.metadata.docs.rs] diff --git a/src/checker.rs b/src/checker.rs index 9d00fb6..ad55d36 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -1,11 +1,5 @@ use crate::finder::Checker; -#[cfg(any(unix, target_os = "wasi"))] -use std::ffi::CString; use std::fs; -#[cfg(unix)] -use std::os::unix::ffi::OsStrExt; -#[cfg(target_os = "wasi")] -use std::os::wasi::ffi::OsStrExt; use std::path::Path; pub struct ExecutableChecker; @@ -19,9 +13,8 @@ impl ExecutableChecker { impl Checker for ExecutableChecker { #[cfg(any(unix, target_os = "wasi"))] fn is_valid(&self, path: &Path) -> bool { - CString::new(path.as_os_str().as_bytes()) - .map(|c| unsafe { libc::access(c.as_ptr(), libc::X_OK) == 0 }) - .unwrap_or(false) + use rustix::fs as rfs; + rfs::access(path, rfs::Access::EXEC_OK).is_ok() } #[cfg(windows)] 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;