Skip to content

Commit

Permalink
Improve fd_close wasi test: explicitly close file
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Oct 23, 2019
1 parent 3a87edc commit 5353af7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/wasi-tests/wasitests/fd_close.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Successfully closed file!
Successfully closed stderr!
Successfully closed stdin!
9 changes: 9 additions & 0 deletions lib/wasi-tests/wasitests/fd_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ fn main() {

#[cfg(target_os = "wasi")]
{
let file_fd = file.as_raw_fd();
let stdout_fd = std::io::stdout().as_raw_fd();
let stderr_fd = std::io::stderr().as_raw_fd();
let stdin_fd = std::io::stdin().as_raw_fd();

let result = unsafe { fd_close(file_fd) };
if result == 0 {
println!("Successfully closed file!")
} else {
println!("Could not close file");
}

let result = unsafe { fd_close(stderr_fd) };
if result == 0 {
println!("Successfully closed stderr!")
Expand All @@ -48,6 +56,7 @@ fn main() {
}
#[cfg(not(target_os = "wasi"))]
{
println!("Successfully closed file!");
println!("Successfully closed stderr!");
println!("Successfully closed stdin!");
}
Expand Down
Binary file modified lib/wasi-tests/wasitests/fd_close.wasm
Binary file not shown.

0 comments on commit 5353af7

Please sign in to comment.