INNER CODE UNIT · Rust

find_on_path

ngless-toolkit/ngless · src/lib.rs:271

fn find_on_path(fname: &str) -> Option<String> {
    let path = std::env::var_os("PATH")?;
    for dir in std::env::split_paths(&path) {
        let candidate = dir.join(fname);
        if candidate.is_file() && is_executable(&candidate) {
            return Some(candidate.to_string_lossy().into_owned());
        }
    }
    None
}

/// Whether `path` is executable by the current process. On Unix this checks the executable
/// permission bits; on other platforms existence as a file is taken as sufficient.
fn is_executable(path: &std::path::Path) -> bool {
    #[cfg(unix)]
    {
        use std::os::unix::fs::PermissionsExt;
        match std::fs::metadata(path) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…