Skip to content

Commit cdd146b

Browse files
committed
Add std::os::self_exe_name()
1 parent fce7922 commit cdd146b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/libstd/os.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ pub fn dll_filename(base: &str) -> ~str {
337337
format!("{}{}{}", consts::DLL_PREFIX, base, consts::DLL_SUFFIX)
338338
}
339339

340-
/// Optionally returns the filesystem path to the current executable which is
340+
/// Optionally returns the filesystem path of the current executable which is
341341
/// running. If any failure occurs, None is returned.
342-
pub fn self_exe_path() -> Option<Path> {
342+
pub fn self_exe_name() -> Option<Path> {
343343

344344
#[cfg(target_os = "freebsd")]
345345
fn load_self() -> Option<~[u8]> {
@@ -402,7 +402,14 @@ pub fn self_exe_path() -> Option<Path> {
402402
}
403403
}
404404

405-
load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p }))
405+
load_self().and_then(Path::new_opt)
406+
}
407+
408+
/// Optionally returns the filesystem path to the current executable which is
409+
/// running. Like self_exe_name() but without the binary's name.
410+
/// If any failure occurs, None is returned.
411+
pub fn self_exe_path() -> Option<Path> {
412+
self_exe_name().map(|mut p| { p.pop(); p })
406413
}
407414

408415
/**
@@ -1310,6 +1317,17 @@ mod tests {
13101317
assert_eq!(getenv(n), option::Some(s));
13111318
}
13121319
1320+
#[test]
1321+
fn test_self_exe_name() {
1322+
let path = os::self_exe_name();
1323+
assert!(path.is_some());
1324+
let path = path.unwrap();
1325+
debug!("{:?}", path.clone());
1326+
1327+
// Hard to test this function
1328+
assert!(path.is_absolute());
1329+
}
1330+
13131331
#[test]
13141332
fn test_self_exe_path() {
13151333
let path = os::self_exe_path();

0 commit comments

Comments
 (0)