diff --git a/src/header/grp/mod.rs b/src/header/grp/mod.rs index e30a1d1557014db30b7c5f162be68a5c63cef47d..282ffb6cf588bfb4ca7df8f5060a021529e08f8f 100644 --- a/src/header/grp/mod.rs +++ b/src/header/grp/mod.rs @@ -31,6 +31,12 @@ use crate::{ use super::{errno::*, string::strncmp}; +#[cfg(target_os = "linux")] +const SEPARATOR: char = ':'; + +#[cfg(target_os = "redox")] +const SEPARATOR: char = ';'; + #[derive(Clone, Copy, Debug)] struct DestBuffer { ptr: *mut u8, @@ -136,7 +142,7 @@ fn parse_grp(line: String, destbuf: Option<DestBuffer>) -> Result<OwnedGrp, Erro let mut buffer = buffer .into_iter() - .map(|i| if i == b':' { b'\0' } else { i }) + .map(|i| if i == SEPARATOR as u8 { b'\0' } else { i }) .chain([b'\0']) .collect::<Vec<_>>(); let mut buffer = buffer.split_mut(|i| *i == b'\0'); @@ -146,7 +152,11 @@ fn parse_grp(line: String, destbuf: Option<DestBuffer>) -> Result<OwnedGrp, Erro let mut vec: Vec<u8> = Vec::new(); let gr_name = buffer.next().ok_or(Error::EOF)?.to_vec(); - let gr_passwd = buffer.next().ok_or(Error::EOF)?.to_vec(); + let gr_passwd = if cfg!(target_os = "redox") { + Vec::new() + } else { + buffer.next().ok_or(Error::EOF)?.to_vec() + }; gr_gid = String::from_utf8(buffer.next().ok_or(Error::EOF)?.to_vec()) .map_err(|err| Error::FromUtf8Error(err))? .parse::<gid_t>() @@ -353,7 +363,7 @@ pub unsafe extern "C" fn getgrouplist( match line { Err(_) => return 0, Ok(line) => { - let mut parts = line.split(':'); + let mut parts = line.split(SEPARATOR); let group_name = parts.next().unwrap_or(""); let group_password = parts.next().unwrap_or(""); diff --git a/src/header/pwd/mod.rs b/src/header/pwd/mod.rs index 1d1df9212bcc27824383ca1249343a03b5b6eecc..1919a887d2f1f9cb56146fd647185e6322dd7348 100644 --- a/src/header/pwd/mod.rs +++ b/src/header/pwd/mod.rs @@ -24,6 +24,12 @@ use self::linux as sys; #[cfg(target_os = "redox")] use self::redox as sys; +#[cfg(target_os = "linux")] +const SEPARATOR: u8 = b':'; + +#[cfg(target_os = "redox")] +const SEPARATOR: u8 = b';'; + #[repr(C)] #[derive(Debug)] pub struct passwd { @@ -128,9 +134,9 @@ fn getpwent_r( return Err(Cause::Eof); } - // Replace all occurences of ':' with terminating NUL byte + // Replace all occurences of seperator with terminating NUL byte let mut start = 0; - while let Some(i) = memchr::memchr(b':', &buf[start..]) { + while let Some(i) = memchr::memchr(SEPARATOR, &buf[start..]) { buf[start + i] = 0; start += i + 1; }