Hi,
I wrote this Program that closes the StdOut FD and after that tries to write to StdOut.
My question is why the match statement chooses the Ok(_) branch.
If I run the program with strace I get this output:
write(1, "test", 4) = -1 EBADF (Bad file descriptor)
write(2, "Success\n", 8) = 8
Shouldn't rust execute the Err branch? What am I missing?
The source
use std::io::Write;
use std::os::unix::io::{AsRawFd, FromRawFd};
fn main() {
let id = std::io::stdout().as_raw_fd();
let f = unsafe {
std::fs::File::from_raw_fd(id);
};
drop(f);
let out = std::io::stdout();
{
let mut out = out.lock();
out.write_all(b"test").unwrap();
let out_res = out.flush();
match out_res {
Ok(_) => eprintln!("Success"),
Err(_) => eprintln!("Failed"),
}
}
}