@@ -2,7 +2,7 @@ use super::{abi, error};
2
2
use crate :: {
3
3
ffi:: { CStr , CString , OsStr , OsString } ,
4
4
fmt,
5
- io:: { self , IoSlice , IoSliceMut , SeekFrom } ,
5
+ io:: { self , IoSlice , IoSliceMut , ReadBuf , SeekFrom } ,
6
6
mem:: MaybeUninit ,
7
7
os:: raw:: { c_int, c_short} ,
8
8
os:: solid:: ffi:: OsStrExt ,
@@ -339,6 +339,32 @@ impl File {
339
339
}
340
340
}
341
341
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
+
342
368
pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
343
369
crate :: io:: default_read_vectored ( |buf| self . read ( buf) , bufs)
344
370
}
0 commit comments