]>
git.proxmox.com Git - rustc.git/blob - src/libstd/sys/sgx/stdio.rs
1 use fortanix_sgx_abi
as abi
;
8 use crate::sys
::fd
::FileDesc
;
11 pub struct Stdout(());
12 pub struct Stderr(());
14 fn with_std_fd
<F
: FnOnce(&FileDesc
) -> R
, R
>(fd
: abi
::Fd
, f
: F
) -> R
{
15 let fd
= FileDesc
::new(fd
);
22 pub fn new() -> io
::Result
<Stdin
> {
27 impl io
::Read
for Stdin
{
28 fn read(&mut self, buf
: &mut [u8]) -> io
::Result
<usize> {
29 with_std_fd(abi
::FD_STDIN
, |fd
| fd
.read(buf
))
34 pub fn new() -> io
::Result
<Stdout
> {
39 impl io
::Write
for Stdout
{
40 fn write(&mut self, buf
: &[u8]) -> io
::Result
<usize> {
41 with_std_fd(abi
::FD_STDOUT
, |fd
| fd
.write(buf
))
44 fn flush(&mut self) -> io
::Result
<()> {
45 with_std_fd(abi
::FD_STDOUT
, |fd
| fd
.flush())
50 pub fn new() -> io
::Result
<Stderr
> {
55 impl io
::Write
for Stderr
{
56 fn write(&mut self, buf
: &[u8]) -> io
::Result
<usize> {
57 with_std_fd(abi
::FD_STDERR
, |fd
| fd
.write(buf
))
60 fn flush(&mut self) -> io
::Result
<()> {
61 with_std_fd(abi
::FD_STDERR
, |fd
| fd
.flush())
65 pub const STDIN_BUF_SIZE
: usize = crate::sys_common
::io
::DEFAULT_BUF_SIZE
;
67 pub fn is_ebadf(err
: &io
::Error
) -> bool
{
68 // FIXME: Rust normally maps Unix EBADF to `Other`
69 err
.raw_os_error() == Some(abi
::Error
::BrokenPipe
as _
)
72 pub fn panic_output() -> Option
<impl io
::Write
> {
73 super::abi
::panic
::SgxPanicOutput
::new()
76 // This function is needed by libunwind. The symbol is named in pre-link args
77 // for the target specification, so keep that in sync.
80 pub unsafe extern "C" fn __rust_print_err(m
: *mut u8, s
: i32) {
84 let buf
= slice
::from_raw_parts(m
as *const u8, s
as _
);
85 if let Ok(s
) = str::from_utf8(&buf
[..buf
.iter().position(|&b
| b
== 0).unwrap_or(buf
.len())]) {