Skip to content

Commit

Permalink
Try #1213:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Feb 13, 2020
2 parents f2d9a49 + 62e1526 commit 0e402ad
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
15 changes: 15 additions & 0 deletions lib/wasi-tests/tests/wasitests/isatty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// !!! THIS IS A GENERATED FILE !!!
// ANY MANUAL EDITS MAY BE OVERWRITTEN AT ANY TIME
// Files autogenerated with cargo build (build/wasitests.rs).

#[test]
fn test_isatty() {
assert_wasi_output!(
"../../wasitests/isatty.wasm",
"isatty",
vec![],
vec![],
vec![],
"../../wasitests/isatty.out"
);
}
1 change: 1 addition & 0 deletions lib/wasi-tests/tests/wasitests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod file_metadata;
mod fs_sandbox_test;
mod fseek;
mod hello;
mod isatty;
mod mapdir;
mod path_link;
mod path_rename;
Expand Down
3 changes: 3 additions & 0 deletions lib/wasi-tests/wasitests/isatty.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
stdin: 1
stdout: 1
stderr: 1
11 changes: 11 additions & 0 deletions lib/wasi-tests/wasitests/isatty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// use libc::isatty;

extern "C" {
pub fn isatty(fd: i32) -> i32;
}

fn main() {
println!("stdin: {}", unsafe { isatty(0) });
println!("stdout: {}", unsafe { isatty(1) });
println!("stderr: {}", unsafe { isatty(2) });
}
Binary file added lib/wasi-tests/wasitests/isatty.wasm
Binary file not shown.
22 changes: 19 additions & 3 deletions lib/wasi/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,28 @@ impl WasiFs {

pub fn fdstat(&self, fd: __wasi_fd_t) -> Result<__wasi_fdstat_t, __wasi_errno_t> {
match fd {
__WASI_STDOUT_FILENO => {
__WASI_STDIN_FILENO => {
return Ok(__wasi_fdstat_t {
fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE,
fs_flags: 0,
fs_rights_base: ALL_RIGHTS,
fs_rights_inheriting: ALL_RIGHTS,
fs_rights_base: STDIN_DEFAULT_RIGHTS,
fs_rights_inheriting: 0,
})
}
__WASI_STDOUT_FILENO => {
return Ok(__wasi_fdstat_t {
fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE,
fs_flags: __WASI_FDFLAG_APPEND,
fs_rights_base: STDOUT_DEFAULT_RIGHTS,
fs_rights_inheriting: 0,
})
}
__WASI_STDERR_FILENO => {
return Ok(__wasi_fdstat_t {
fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE,
fs_flags: __WASI_FDFLAG_APPEND,
fs_rights_base: STDERR_DEFAULT_RIGHTS,
fs_rights_inheriting: 0,
})
}
_ => (),
Expand Down

0 comments on commit 0e402ad

Please sign in to comment.