Skip to content

Commit 874514c

Browse files
committed
kmc-solid: Add std::sys::solid::fs::File::read_buf
Catching up with commit 3b263ce
1 parent ed7a206 commit 874514c

File tree

1 file changed

+27
-1
lines changed
  • library/std/src/sys/solid

1 file changed

+27
-1
lines changed

library/std/src/sys/solid/fs.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{abi, error};
22
use crate::{
33
ffi::{CStr, CString, OsStr, OsString},
44
fmt,
5-
io::{self, IoSlice, IoSliceMut, SeekFrom},
5+
io::{self, IoSlice, IoSliceMut, ReadBuf, SeekFrom},
66
mem::MaybeUninit,
77
os::raw::{c_int, c_short},
88
os::solid::ffi::OsStrExt,
@@ -339,6 +339,32 @@ impl File {
339339
}
340340
}
341341

342+
pub fn read_buf(&self, buf: &mut ReadBuf<'_>) -> io::Result<()> {
343+
unsafe {
344+
let len = buf.remaining();
345+
let mut out_num_bytes = MaybeUninit::uninit();
346+
error::SolidError::err_if_negative(abi::SOLID_FS_Read(
347+
self.fd.raw(),
348+
buf.unfilled_mut().as_mut_ptr() as *mut u8,
349+
len,
350+
out_num_bytes.as_mut_ptr(),
351+
))
352+
.map_err(|e| e.as_io_error())?;
353+
354+
// Safety: `out_num_bytes` is filled by the successful call to
355+
// `SOLID_FS_Read`
356+
let num_bytes_read = out_num_bytes.assume_init();
357+
358+
// Safety: `num_bytes_read` bytes were written to the unfilled
359+
// portion of the buffer
360+
buf.assume_init(num_bytes_read);
361+
362+
buf.add_filled(num_bytes_read);
363+
364+
Ok(())
365+
}
366+
}
367+
342368
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
343369
crate::io::default_read_vectored(|buf| self.read(buf), bufs)
344370
}

0 commit comments

Comments
 (0)