use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
pub const EXECUTABLE_EXTENSION: Option<&str> = None;
pub fn file_name(bare: &str) -> String {
match EXECUTABLE_EXTENSION {
Some(extension) => format!("{bare}.{extension}"),
None => bare.to_owned(),
}
}
pub fn sibling_of_current_image(bare: &str) -> Option<PathBuf> {
let current = std::env::current_exe().ok()?;
let candidate = current.parent()?.join(file_name(bare));
candidate.is_file().then_some(candidate)
}
pub fn native_library_name(stem: &OsStr) -> OsString {
let mut name = stem.to_os_string();
if Path::new(stem).extension().is_none() {
name.push(".dylib");
}
name
}
pub fn find_in_paths(name: &OsStr, directories: &[PathBuf]) -> Option<PathBuf> {
directories
.iter()
.map(|directory| directory.join(name))
.find(|candidate| candidate.is_file())
}
pub fn stem_matches(path: &OsStr, expected: &str) -> bool {
Path::new(path).file_stem() == Some(OsStr::new(expected))
}
pub fn unlock_for_replacement(_image: &Path) -> std::io::Result<bool> {
Ok(false)
}