Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kmc-solid: Add std::sys::solid::fs::File::read_buf #92117

Merged
merged 1 commit into from
Dec 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion library/std/src/sys/solid/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{abi, error};
use crate::{
ffi::{CStr, CString, OsStr, OsString},
fmt,
io::{self, IoSlice, IoSliceMut, SeekFrom},
io::{self, IoSlice, IoSliceMut, ReadBuf, SeekFrom},
mem::MaybeUninit,
os::raw::{c_int, c_short},
os::solid::ffi::OsStrExt,
Expand Down Expand Up @@ -339,6 +339,32 @@ impl File {
}
}

pub fn read_buf(&self, buf: &mut ReadBuf<'_>) -> io::Result<()> {
unsafe {
let len = buf.remaining();
let mut out_num_bytes = MaybeUninit::uninit();
error::SolidError::err_if_negative(abi::SOLID_FS_Read(
self.fd.raw(),
buf.unfilled_mut().as_mut_ptr() as *mut u8,
len,
out_num_bytes.as_mut_ptr(),
))
.map_err(|e| e.as_io_error())?;

// Safety: `out_num_bytes` is filled by the successful call to
// `SOLID_FS_Read`
let num_bytes_read = out_num_bytes.assume_init();

// Safety: `num_bytes_read` bytes were written to the unfilled
// portion of the buffer
buf.assume_init(num_bytes_read);

buf.add_filled(num_bytes_read);

Ok(())
}
}

pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
crate::io::default_read_vectored(|buf| self.read(buf), bufs)
}
Expand Down