about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-01-24 06:06:33 -0800
committerbors <bors@rust-lang.org>2014-01-24 06:06:33 -0800
commita5ab960d2e443f61511b19ad80221d1f99fd0692 (patch)
treef47ca2e39f6c232875819f9c996a4b084de61bc0 /src/libstd
parent5675f2813f86ccc6d94251f447661939d9ac3a63 (diff)
parent51103c89d06953fc534572723f030b292fabe73d (diff)
downloadrust-a5ab960d2e443f61511b19ad80221d1f99fd0692.tar.gz
rust-a5ab960d2e443f61511b19ad80221d1f99fd0692.zip
auto merge of #11750 : bnoordhuis/rust/follow-rustc-symlink, r=thestinger
Before this commit, rustc looked in `dirname $0`/../lib for libraries
but that doesn't work when rustc is invoked through a symlink.

This commit makes rustc look in `dirname $(readlink $0)`/../lib, i.e.
it first canonicalizes the symlink before walking up the directory tree.

Fixes #3632.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/os.rs24
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());