Kaynağa Gözat

Untested fix for pwd.h on redox

jD91mZM2 6 yıl önce
ebeveyn
işleme
9e9b850b90
3 değiştirilmiş dosya ile 29 ekleme ve 7 silme
  1. 7 0
      src/header/pwd/linux.rs
  2. 7 7
      src/header/pwd/mod.rs
  3. 15 0
      src/header/pwd/redox.rs

+ 7 - 0
src/header/pwd/linux.rs

@@ -0,0 +1,7 @@
+pub fn split(line: &[u8]) -> [&[u8]; 7] {
+    let mut parts: [&[u8]; 7] = [&[]; 7];
+    for (i, part) in line.splitn(7, |b| *b == b':').enumerate() {
+        parts[i] = part;
+    }
+    parts
+}

+ 7 - 7
src/header/pwd/mod.rs

@@ -6,9 +6,14 @@ use c_str::CStr;
 use header::{errno, fcntl};
 use platform;
 use platform::types::*;
-use platform::Sys;
 use platform::{Line, RawFile, RawLineBuffer};
 
+#[cfg(target_os = "linux")] mod linux;
+#[cfg(target_os = "redox")] mod redox;
+
+#[cfg(target_os = "linux")] use self::linux as sys;
+#[cfg(target_os = "redox")] use self::redox as sys;
+
 #[repr(C)]
 pub struct passwd {
     pw_name: *mut c_char,
@@ -65,14 +70,9 @@ where
         };
 
         // Parse into passwd
-        let mut parts: [&[u8]; 7] = [&[]; 7];
-        for (i, part) in line.splitn(7, |b| *b == b':').enumerate() {
-            parts[i] = part;
-        }
+        let mut parts: [&[u8]; 7] = sys::split(line);
 
         if !callback(&parts) {
-            // TODO when nll becomes a thing:
-            // buf.drain(..newline + 1);
             continue;
         }
 

+ 15 - 0
src/header/pwd/redox.rs

@@ -0,0 +1,15 @@
+pub fn split(line: &[u8]) -> [&[u8]; 7] {
+    let mut parts: [&[u8]; 7] = [&[]; 7];
+    let mut iter = line.split(|b| *b == b';');
+
+    parts[0] = iter.next().unwrap_or(&[]);
+    // Skip passwd
+    for i in 0..2 {
+        parts[2+i] = iter.next().unwrap_or(&[]);
+    }
+    // Skip gecos
+    for i in 0..2 {
+        parts[5+i] = iter.next().unwrap_or(&[]);
+    }
+    parts
+}