running_process_platform_internal/platform_linux/executable.rs
1//! linux executable naming and image-relative discovery.
2
3use std::path::PathBuf;
4
5/// File-name extension the host requires on a runnable image, if any.
6pub const EXECUTABLE_EXTENSION: Option<&str> = None;
7
8/// Spell `bare` the way this host names an executable file.
9///
10/// Callers name the *program*; the host decides whether that program is a file
11/// called `bare` or `bare.exe`. Only the file spelling changes here — PATH
12/// search order and `PATHEXT` are search concerns, not naming ones.
13pub fn file_name(bare: &str) -> String {
14 match EXECUTABLE_EXTENSION {
15 Some(extension) => format!("{bare}.{extension}"),
16 None => bare.to_owned(),
17 }
18}
19
20/// Path to a sibling program installed beside the running image.
21///
22/// Returns `None` when the current image cannot be resolved, has no parent
23/// directory, or the sibling is not a file — all of which mean the same thing
24/// to a caller: this program is not installed next to us, look elsewhere.
25pub fn sibling_of_current_image(bare: &str) -> Option<PathBuf> {
26 let current = std::env::current_exe().ok()?;
27 let candidate = current.parent()?.join(file_name(bare));
28 candidate.is_file().then_some(candidate)
29}