From ea0a7b278950f372655b3e6e62ea4007244d7c21 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 4 Jan 2020 09:09:15 +0100 Subject: [PATCH] add support of the unikernel RustyHermit - use the crate hermit-abi as interface to the kernel --- Cargo.toml | 3 +++ src/lib.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 7351a2f..d3cd562 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,9 @@ travis-ci = { repository = "softprops/atty" } [target.'cfg(unix)'.dependencies] libc = { version = "0.2", default-features = false } +[target.'cfg(target_os = "hermit")'.dependencies] +hermit-abi = "0.1.6" + [target.'cfg(windows)'.dependencies.winapi] version = "0.3" features = ["consoleapi", "processenv", "minwinbase", "minwindef", "winbase"] diff --git a/src/lib.rs b/src/lib.rs index 89b7555..501cad6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,19 @@ pub fn is(stream: Stream) -> bool { unsafe { libc::isatty(fd) != 0 } } +/// returns true if this is a tty +#[cfg(target_os = "hermit")] +pub fn is(stream: Stream) -> bool { + extern crate hermit_abi; + + let fd = match stream { + Stream::Stdout => hermit_abi::STDOUT_FILENO, + Stream::Stderr => hermit_abi::STDERR_FILENO, + Stream::Stdin => hermit_abi::STDIN_FILENO, + }; + hermit_abi::isatty(fd) +} + /// returns true if this is a tty #[cfg(windows)] pub fn is(stream: Stream) -> bool {