Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 19b8643

Browse files
committedMar 11, 2025
Implement read_buf for Hermit
1 parent 9038494 commit 19b8643

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed
 

‎library/std/src/sys/fs/hermit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl File {
396396
}
397397

398398
pub fn read_buf(&self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
399-
crate::io::default_read_buf(|buf| self.read(buf), cursor)
399+
self.0.read_buf(cursor)
400400
}
401401

402402
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {

‎library/std/src/sys/pal/hermit/fd.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use super::hermit_abi;
44
use crate::cmp;
5-
use crate::io::{self, IoSlice, IoSliceMut, Read, SeekFrom};
5+
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, SeekFrom};
66
use crate::os::hermit::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
77
use crate::sys::{cvt, unsupported};
88
use crate::sys_common::{AsInner, FromInner, IntoInner};
@@ -23,6 +23,18 @@ impl FileDesc {
2323
Ok(result as usize)
2424
}
2525

26+
pub fn read_buf(&self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
27+
let result = cvt(unsafe {
28+
hermit_abi::read(
29+
self.fd.as_raw_fd(),
30+
buf.as_mut().as_mut_ptr() as *mut u8,
31+
buf.capacity(),
32+
)
33+
})?;
34+
unsafe { buf.advance_unchecked(result as usize) };
35+
Ok(())
36+
}
37+
2638
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
2739
let ret = cvt(unsafe {
2840
hermit_abi::readv(

‎library/std/src/sys/stdio/unix.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use hermit_abi::{EBADF, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
33
#[cfg(target_family = "unix")]
44
use libc::{EBADF, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
55

6-
#[cfg(target_family = "unix")]
7-
use crate::io::BorrowedCursor;
8-
use crate::io::{self, IoSlice, IoSliceMut};
6+
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut};
97
use crate::mem::ManuallyDrop;
108
#[cfg(target_os = "hermit")]
119
use crate::os::hermit::io::FromRawFd;
@@ -28,7 +26,6 @@ impl io::Read for Stdin {
2826
unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(STDIN_FILENO)).read(buf) }
2927
}
3028

31-
#[cfg(not(target_os = "hermit"))]
3229
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> io::Result<()> {
3330
unsafe { ManuallyDrop::new(FileDesc::from_raw_fd(STDIN_FILENO)).read_buf(buf) }
3431
}

0 commit comments

Comments
 (0)
Failed to load comments.