1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! [`whereami`](https://github.com/gpakosz/whereami) for Rust.
//!
//! Used for checking where the current executable/DLL is.
//!
//! # Examples:
//!
//! ```
//! println!("This executable is at {}", whereami::executable_path().unwrap().to_str().unwrap());
//! println!("This exec/DLL is at {}", whereami::module_path().unwrap().to_str().unwrap());
//! ```


extern crate libc;

mod native;
mod implementation;

use std::path::PathBuf;


/// Returns the path of the current executable or `None` if acquiring thereof failed.
///
/// # Examples:
///
/// ```
/// # use whereami::executable_path;
/// println!("This executable is at {}", executable_path().unwrap().to_str().unwrap());
/// ```
pub fn executable_path() -> Option<PathBuf> {
    implementation::get_path(native::wai_getExecutablePath)
}

/// Returns the path of the current module or `None` if acquiring thereof failed.
///
/// Note: this is not the Rust `mod`, but rather an OS module
///       (most of the time: a DLL)
///
/// # Examples:
///
/// ```
/// # use whereami::module_path;
/// println!("This exec/DLL is at {}", module_path().unwrap().to_str().unwrap());
/// ```
pub fn module_path() -> Option<PathBuf> {
    implementation::get_path(native::wai_getModulePath)
}