process_path

September 12, 2022 · View on GitHub

A Rust library to get the path of the currently executing process or the the current dynamic library.

The latter is particularly useful for ‘plug-in‘ type dynamic libraries that need to load resources stored relative to the location of the library in the file system.

Usage

Add this to your Cargo.toml:

[dependencies]
process_path = "0.1.4"

and this to your crate root:

use process_path;

Example

This program prints its path to stdout:

use process_path::get_executable_path;

fn main() {
    let path = get_executable_path();
    match path {
        None => println!("The process path could not be determined"),
        Some(path) => println!("{:?}", path)
    }
}

Supported Platforms

PlatformUnderlying API get_executable_path()get_dylib_path()
Linuxreadlink(/proc/self/exe)dladdr()
FreeBSDsysctl(3) or readlink(/proc/curproc/file)dladdr()
NetBSDreadlink(/proc/curproc/exe)dladdr()
DragonflyBSDreadlink(/proc/curproc/file)dladdr()
macOS_NSGetExecutablePath()dladdr()
WindowsGetModuleFileName()GetModuleHandleEx()
illumosreadlink(/proc/self/exe)dladdr()

License

Copyright Wesley Wiser and process_path contributors.

Licensed under either of

at your option.