Skip to content

Commit

Permalink
Rollup merge of rust-lang#92117 - solid-rs:fix-kmc-solid-read-buf, r=…
Browse files Browse the repository at this point in the history
…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 rust-lang#81156 and fix the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets..
  • Loading branch information
matthiaskrgr committed Dec 22, 2021
2 parents 9f68b6e + 874514c commit 554ad50
Showing 1 changed file with 27 additions and 1 deletion.
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

0 comments on commit 554ad50

Please sign in to comment.