about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorIan Douglas Scott <ian@iandouglasscott.com>2017-08-18 15:56:13 -0700
committerIan Douglas Scott <ian@iandouglasscott.com>2017-08-18 16:07:29 -0700
commite0f0fd08b5e823561848c9541ac432eb30b976bd (patch)
treeeb57e87e43eb724a62f23034aa5d95932239609a /src/libstd
parentb272f6ca05e9210dbe6c605a301d5a16007f322f (diff)
downloadrust-e0f0fd08b5e823561848c9541ac432eb30b976bd.tar.gz
rust-e0f0fd08b5e823561848c9541ac432eb30b976bd.zip
Correct has_root() on Redox
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/path.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index 866b65ac7e4..5757d447c54 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -323,6 +323,20 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr {
     mem::transmute(s)
 }
 
+// Detect scheme on Redox
+#[inline]
+#[allow(unused_variables)]
+fn has_scheme(s: &[u8]) -> bool {
+    #[cfg(target_os = "redox")]
+    {
+        s.split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
+    }
+    #[cfg(not(target_os = "redox"))]
+    {
+        false
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // Cross-platform, iterator-independent parsing
 ////////////////////////////////////////////////////////////////////////////////
@@ -605,6 +619,9 @@ pub struct Components<'a> {
     // normalization, e.g.  \\server\share == \\server\share\.
     has_physical_root: bool,
 
+    // For Redox
+    has_scheme: bool,
+
     // The iterator is double-ended, and these two states keep track of what has
     // been produced from either end
     front: State,
@@ -725,7 +742,7 @@ impl<'a> Components<'a> {
 
     /// Is the *original* path rooted?
     fn has_root(&self) -> bool {
-        if self.has_physical_root {
+        if self.has_physical_root || self.has_scheme {
             return true;
         }
         if let Some(p) = self.prefix {
@@ -1692,8 +1709,7 @@ impl Path {
         #[cfg(target_os = "redox")]
         {
             // FIXME: Allow Redox prefixes
-            use os::unix::ffi::OsStrExt;
-            self.as_os_str().as_bytes().split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':')
+            has_scheme(self.as_u8_slice())
         }
     }
 
@@ -2059,6 +2075,7 @@ impl Path {
             path: self.as_u8_slice(),
             prefix,
             has_physical_root: has_physical_root(self.as_u8_slice(), prefix),
+            has_scheme: has_scheme(self.as_u8_slice()),
             front: State::Prefix,
             back: State::Body,
         }