From a2991cc9c0092f0bab182971900a89442126581f Mon Sep 17 00:00:00 2001 From: LI Qing Date: Thu, 14 Jul 2022 17:02:16 +0800 Subject: [PATCH] Add seek support for stdin and stdout --- src/libos/src/fs/stdio.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libos/src/fs/stdio.rs b/src/libos/src/fs/stdio.rs index 66a26b8a..f11f6bc5 100644 --- a/src/libos/src/fs/stdio.rs +++ b/src/libos/src/fs/stdio.rs @@ -231,6 +231,16 @@ impl File for StdoutFile { Ok(()) } + fn seek(&self, pos: SeekFrom) -> Result { + 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 { self } @@ -411,6 +421,16 @@ impl File for StdinFile { Ok(()) } + fn seek(&self, pos: SeekFrom) -> Result { + 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 { self }