mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 03:23:25 +00:00
Rollup merge of #92117 - solid-rs:fix-kmc-solid-read-buf, r=yaahc
kmc-solid: Add `std::sys::solid::fs::File::read_buf` This PR adds `std::sys::solid::fs::File::read_buf` to catch up with the changes introduced by #81156 and fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets..
This commit is contained in:
commit
554ad50fa2
@ -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,
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user