about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2012-01-09 16:11:25 -0800
committerGraydon Hoare <graydon@mozilla.com>2012-01-09 16:12:47 -0800
commitf6ecbe88ca67769ccb9def337ada9ae25235e00e (patch)
tree292d5c5620c939069664e515bf1ecd1d31ed0ade /src/libstd
parenta736669fb686d1a44f47d9624a9ed2aa1e072413 (diff)
downloadrust-f6ecbe88ca67769ccb9def337ada9ae25235e00e.tar.gz
rust-f6ecbe88ca67769ccb9def337ada9ae25235e00e.zip
Fix rpath bug.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 2a65559db5a..4e97603e177 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -81,17 +81,20 @@ Function: connect
 
 Connects to path segments
 
-Given paths `pre` and `post` this function will return a path
-that is equal to `post` appended to `pre`, inserting a path separator
-between the two as needed.
+Given paths `pre` and `post, removes any trailing path separator on `pre` and
+any leading path separator on `post`, and returns the concatenation of the two
+with a single path separator between them.
 */
-fn connect(pre: path, post: path) -> path {
-    let len = str::byte_len(pre);
-    ret if pre[len - 1u] == os_fs::path_sep as u8 {
 
-            // Trailing '/'?
-            pre + post
-        } else { pre + path_sep() + post };
+fn connect(pre: path, post: path) -> path {
+    let pre_ = pre;
+    let post_ = post;
+    let sep = os_fs::path_sep as u8;
+    let pre_len = str::byte_len(pre);
+    let post_len = str::byte_len(post);
+    if pre_len > 1u && pre[pre_len-1u] == sep { str::pop_byte(pre_); }
+    if post_len > 1u && post[0] == sep { str::shift_byte(post_); }
+    ret pre_ + path_sep() + post_;
 }
 
 /*