mirror of
https://github.com/openharmony/third_party_rust_rustix.git
synced 2026-07-18 21:05:30 -04:00
39da9d142c
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.
42 lines
1.0 KiB
Rust
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!()
|
|
}
|