1 use fortanix_sgx_abi as abi;
4 use crate::sys::fd::FileDesc;
10 fn with_std_fd<F: FnOnce(&FileDesc) -> R, R>(fd: abi::Fd, f: F) -> R {
11 let fd = FileDesc::new(fd);
18 pub fn new() -> io::Result<Stdin> { Ok(Stdin(())) }
21 impl io::Read for Stdin {
22 fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
23 with_std_fd(abi::FD_STDIN, |fd| fd.read(buf))
28 pub fn new() -> io::Result<Stdout> { Ok(Stdout(())) }
31 impl io::Write for Stdout {
32 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
33 with_std_fd(abi::FD_STDOUT, |fd| fd.write(buf))
36 fn flush(&mut self) -> io::Result<()> {
37 with_std_fd(abi::FD_STDOUT, |fd| fd.flush())
42 pub fn new() -> io::Result<Stderr> { Ok(Stderr(())) }
45 impl io::Write for Stderr {
46 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
47 with_std_fd(abi::FD_STDERR, |fd| fd.write(buf))
50 fn flush(&mut self) -> io::Result<()> {
51 with_std_fd(abi::FD_STDERR, |fd| fd.flush())
55 pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
57 pub fn is_ebadf(err: &io::Error) -> bool {
58 // FIXME: Rust normally maps Unix EBADF to `Other`
59 err.raw_os_error() == Some(abi::Error::BrokenPipe as _)
62 pub fn panic_output() -> Option<impl io::Write> {
63 super::abi::panic::SgxPanicOutput::new()