]> git.lizzy.rs Git - rust.git/commitdiff
Correct has_root() on Redox
authorIan Douglas Scott <ian@iandouglasscott.com>
Fri, 18 Aug 2017 22:56:13 +0000 (15:56 -0700)
committerIan Douglas Scott <ian@iandouglasscott.com>
Fri, 18 Aug 2017 23:07:29 +0000 (16:07 -0700)
src/libstd/path.rs

index 866b65ac7e4c33226718a748f5c2299c4465d01c..5757d447c54d0d6a8ab2c4f2699a3cd11c0d7233 100644 (file)
@@ -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 @@ pub fn as_path(&self) -> &'a Path {
 
     /// 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 @@ pub fn is_absolute(&self) -> bool {
         #[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 @@ pub fn components(&self) -> Components {
             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,
         }