diff options
| author | Diggory Blake <diggsey@googlemail.com> | 2017-12-31 16:40:34 +0000 | 
|---|---|---|
| committer | Diggory Blake <diggsey@googlemail.com> | 2018-01-30 23:22:19 +0000 | 
| commit | 36695a37c52a0e6cc582247a506ab0b3c764b48f (patch) | |
| tree | 4d445b84a19f743550725e4f87373ff5bffae921 /src/libstd/sys/wasm/stdio.rs | |
| parent | def3269a71be2e737cad27418a3dad9f5bd6cd32 (diff) | |
| download | rust-36695a37c52a0e6cc582247a506ab0b3c764b48f.tar.gz rust-36695a37c52a0e6cc582247a506ab0b3c764b48f.zip | |
Implement extensible syscall interface for wasm
Diffstat (limited to 'src/libstd/sys/wasm/stdio.rs')
| -rw-r--r-- | src/libstd/sys/wasm/stdio.rs | 35 | 
1 files changed, 7 insertions, 28 deletions
| diff --git a/src/libstd/sys/wasm/stdio.rs b/src/libstd/sys/wasm/stdio.rs index 0f75f240251..beb19c0ed2c 100644 --- a/src/libstd/sys/wasm/stdio.rs +++ b/src/libstd/sys/wasm/stdio.rs @@ -9,19 +9,19 @@ // except according to those terms. use io; -use sys::{Void, unsupported}; +use sys::{ReadSysCall, WriteSysCall}; -pub struct Stdin(Void); +pub struct Stdin; pub struct Stdout; pub struct Stderr; impl Stdin { pub fn new() -> io::Result<Stdin> { - unsupported() + Ok(Stdin) } - pub fn read(&self, _data: &mut [u8]) -> io::Result<usize> { - match self.0 {} + pub fn read(&self, data: &mut [u8]) -> io::Result<usize> { + Ok(ReadSysCall::perform(0, data)) } } @@ -31,19 +31,7 @@ impl Stdout { } pub fn write(&self, data: &[u8]) -> io::Result<usize> { - // If runtime debugging is enabled at compile time we'll invoke some - // runtime functions that are defined in our src/etc/wasm32-shim.js - // debugging script. Note that this ffi function call is intended - // *purely* for debugging only and should not be relied upon. - if !super::DEBUG { - return unsupported() - } - extern { - fn rust_wasm_write_stdout(data: *const u8, len: usize); - } - unsafe { - rust_wasm_write_stdout(data.as_ptr(), data.len()) - } + WriteSysCall::perform(1, data); Ok(data.len()) } @@ -58,16 +46,7 @@ impl Stderr { } pub fn write(&self, data: &[u8]) -> io::Result<usize> { - // See comments in stdout for what's going on here. - if !super::DEBUG { - return unsupported() - } - extern { - fn rust_wasm_write_stderr(data: *const u8, len: usize); - } - unsafe { - rust_wasm_write_stderr(data.as_ptr(), data.len()) - } + WriteSysCall::perform(2, data); Ok(data.len()) } | 
