Files
third_party_rust_rustix/examples/stdio.rs
T
Dan Gohman 39da9d142c Rename rustix::io_lifetimes to rustix::fd. (#128)
And have it export only the types and traits that rustix uses. This
makes it easier to provide a consistent interface whether the fd
types and traits are defined by the standard library or by Rustix
itself.
2021-12-01 11:32:02 -08:00

42 lines
1.0 KiB
Rust

#[cfg(not(windows))]
use rustix::fd::AsFd;
#[cfg(any(all(linux_raw, feature = "procfs"), all(not(windows), libc)))]
use rustix::io::ttyname;
#[cfg(not(windows))]
use rustix::io::{self, isatty, stderr, stdin, stdout};
#[cfg(not(windows))]
fn main() -> io::Result<()> {
let (stdin, stdout, stderr) = unsafe { (stdin(), stdout(), stderr()) };
println!("Stdin:");
show(&stdin)?;
println!("Stdout:");
show(&stdout)?;
println!("Stderr:");
show(&stderr)?;
Ok(())
}
#[cfg(not(windows))]
fn show<Fd: AsFd>(fd: &Fd) -> io::Result<()> {
if isatty(fd) {
#[cfg(any(all(linux_raw, feature = "procfs"), libc))]
println!(" - ttyname: {}", ttyname(fd, Vec::new())?.to_string_lossy());
println!(" - attrs: {:?}", rustix::io::ioctl_tcgets(fd)?);
println!(" - winsize: {:?}", rustix::io::ioctl_tiocgwinsz(fd)?);
println!(" - ready: {:?}", rustix::io::ioctl_fionread(fd)?);
} else {
println!("Stderr is not a tty");
}
Ok(())
}
#[cfg(windows)]
fn main() {
unimplemented!()
}