Skip to main content

strat9_syscall/
io.rs

1#[derive(Debug)]
2/// Minimal sequential reader wrapper over a syscall file descriptor.
3pub struct IoReader {
4    pub fd: usize,
5    pub offset: usize,
6}
7
8#[derive(Debug)]
9/// Minimal sequential writer wrapper over a syscall file descriptor.
10pub struct IoWriter {
11    pub fd: usize,
12    pub offset: usize,
13}
14
15impl IoReader {
16    /// Create a reader bound to `fd`.
17    pub fn new(fd: usize) -> Self {
18        Self { fd, offset: 0 }
19    }
20
21    #[cfg(feature = "userspace")]
22    /// Read bytes from the underlying file descriptor.
23    pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, super::error::Error> {
24        super::call::read(self.fd, buf)
25    }
26}
27
28impl IoWriter {
29    /// Create a writer bound to `fd`.
30    pub fn new(fd: usize) -> Self {
31        Self { fd, offset: 0 }
32    }
33
34    #[cfg(feature = "userspace")]
35    /// Write bytes to the underlying file descriptor.
36    pub fn write(&mut self, buf: &[u8]) -> Result<usize, super::error::Error> {
37        super::call::write(self.fd, buf)
38    }
39}