Add seek support for stdin and stdout

This commit is contained in:
LI Qing 2022-07-14 17:02:16 +08:00 committed by volcano
parent 0b824d3a98
commit a2991cc9c0

@ -231,6 +231,16 @@ impl File for StdoutFile {
Ok(()) Ok(())
} }
fn seek(&self, pos: SeekFrom) -> Result<off_t> {
let (off, whence) = match pos {
SeekFrom::Start(off) => (off as off_t, 0 /* SEEK_SET */),
SeekFrom::Current(off) => (off as off_t, 1 /* SEEK_CUR */),
SeekFrom::End(off) => (off as off_t, 2 /* SEEK_END */),
};
let offset = try_libc!(libc::ocall::lseek(self.host_fd() as i32, off, whence));
Ok(offset)
}
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }
@ -411,6 +421,16 @@ impl File for StdinFile {
Ok(()) Ok(())
} }
fn seek(&self, pos: SeekFrom) -> Result<off_t> {
let (off, whence) = match pos {
SeekFrom::Start(off) => (off as off_t, 0 /* SEEK_SET */),
SeekFrom::Current(off) => (off as off_t, 1 /* SEEK_CUR */),
SeekFrom::End(off) => (off as off_t, 2 /* SEEK_END */),
};
let offset = try_libc!(libc::ocall::lseek(self.host_fd() as i32, off, whence));
Ok(offset)
}
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
} }