diff options
| author | Niklas Fiekas <niklas.fiekas@backscattering.de> | 2025-04-29 14:30:53 +0200 |
|---|---|---|
| committer | Niklas Fiekas <niklas.fiekas@backscattering.de> | 2025-09-03 20:43:38 +0200 |
| commit | c914c471b9d83f9e6c74b0e6c2c8044efd3a57dd (patch) | |
| tree | ba2b5ba07ab64b051f487a7576cc91ec835c7fa8 /library/std/src/sys/pal | |
| parent | 239e8b1b47b34120287ec36b33228c1e177f0c38 (diff) | |
| download | rust-c914c471b9d83f9e6c74b0e6c2c8044efd3a57dd.tar.gz rust-c914c471b9d83f9e6c74b0e6c2c8044efd3a57dd.zip | |
Add `read_buf` equivalents for positioned reads
Adds the following items under the `read_buf_at` feature: - `std::os::unix::fs::FileExt::read_buf_at` - `std::os::unix::fs::FileExt::read_buf_exact_at` - `std::os::windows::fs::FileExt::seek_read_buf`
Diffstat (limited to 'library/std/src/sys/pal')
| -rw-r--r-- | library/std/src/sys/pal/windows/handle.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/library/std/src/sys/pal/windows/handle.rs b/library/std/src/sys/pal/windows/handle.rs index 82a880faf5f..76c8aa939d3 100644 --- a/library/std/src/sys/pal/windows/handle.rs +++ b/library/std/src/sys/pal/windows/handle.rs @@ -136,6 +136,19 @@ impl Handle { } } + pub fn read_buf_at(&self, mut cursor: BorrowedCursor<'_>, offset: u64) -> io::Result<()> { + // SAFETY: `cursor.as_mut()` starts with `cursor.capacity()` writable bytes + let read = unsafe { + self.synchronous_read(cursor.as_mut().as_mut_ptr(), cursor.capacity(), Some(offset)) + }?; + + // SAFETY: `read` bytes were written to the initialized portion of the buffer + unsafe { + cursor.advance_unchecked(read); + } + Ok(()) + } + pub fn read_to_end(&self, buf: &mut Vec<u8>) -> io::Result<usize> { let mut me = self; |
