diff options
| author | Ben Noordhuis <info@bnoordhuis.nl> | 2014-01-22 22:41:53 +0100 |
|---|---|---|
| committer | Ben Noordhuis <info@bnoordhuis.nl> | 2014-01-22 23:47:12 +0100 |
| commit | cdd146b8954d704a07a4445f00ef8ed0f65da096 (patch) | |
| tree | d91c43bdd22033fb4009c1dd3be4c2d609d53e4f /src/libstd | |
| parent | fce792249e72a181f2ad52413b25b1db643c371f (diff) | |
| download | rust-cdd146b8954d704a07a4445f00ef8ed0f65da096.tar.gz rust-cdd146b8954d704a07a4445f00ef8ed0f65da096.zip | |
Add std::os::self_exe_name()
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/os.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 93762a3cdd5..1b55427fc2d 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -337,9 +337,9 @@ pub fn dll_filename(base: &str) -> ~str { format!("{}{}{}", consts::DLL_PREFIX, base, consts::DLL_SUFFIX) } -/// Optionally returns the filesystem path to the current executable which is +/// Optionally returns the filesystem path of the current executable which is /// running. If any failure occurs, None is returned. -pub fn self_exe_path() -> Option<Path> { +pub fn self_exe_name() -> Option<Path> { #[cfg(target_os = "freebsd")] fn load_self() -> Option<~[u8]> { @@ -402,7 +402,14 @@ pub fn self_exe_path() -> Option<Path> { } } - load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p })) + load_self().and_then(Path::new_opt) +} + +/// Optionally returns the filesystem path to the current executable which is +/// running. Like self_exe_name() but without the binary's name. +/// If any failure occurs, None is returned. +pub fn self_exe_path() -> Option<Path> { + self_exe_name().map(|mut p| { p.pop(); p }) } /** @@ -1311,6 +1318,17 @@ mod tests { } #[test] + fn test_self_exe_name() { + let path = os::self_exe_name(); + assert!(path.is_some()); + let path = path.unwrap(); + debug!("{:?}", path.clone()); + + // Hard to test this function + assert!(path.is_absolute()); + } + + #[test] fn test_self_exe_path() { let path = os::self_exe_path(); assert!(path.is_some()); |
