Small refactor

This commit is contained in:
topjohnwu
2023-06-20 00:19:40 -07:00
parent 81493475f9
commit 2359cfc480
2 changed files with 36 additions and 33 deletions

View File

@@ -12,7 +12,7 @@ use std::{io, mem, ptr, slice};
use libc::{c_char, c_uint, dirent, mode_t, EEXIST, ENOENT, O_CLOEXEC, O_PATH, O_RDONLY, O_RDWR};
use crate::{bfmt_cstr, copy_cstr, cstr, errno, error, LibcReturn, Utf8CStr};
use crate::{bfmt_cstr, copy_cstr, cstr, errno, error, FlatData, LibcReturn, Utf8CStr};
pub fn __open_fd_impl(path: &Utf8CStr, flags: i32, mode: mode_t) -> io::Result<OwnedFd> {
unsafe {
@@ -101,6 +101,7 @@ pub fn mkdirs(path: &Utf8CStr, mode: mode_t) -> io::Result<()> {
pub trait ReadExt {
fn skip(&mut self, len: usize) -> io::Result<()>;
fn read_flat_data<F: FlatData>(&mut self, data: &mut F) -> io::Result<()>;
}
impl<T: Read> ReadExt for T {
@@ -114,6 +115,10 @@ impl<T: Read> ReadExt for T {
}
Ok(())
}
fn read_flat_data<F: FlatData>(&mut self, data: &mut F) -> io::Result<()> {
self.read_exact(data.as_raw_bytes_mut())
}
}
pub trait ReadSeekExt {
@@ -162,7 +167,7 @@ impl<T: BufRead> BufReadExt for T {
return true;
}
if let Some((key, value)) = line.split_once('=') {
return f(key, value);
return f(key.trim(), value.trim());
}
true
});