From cc744d30c08a07b8d72dc5d918572198aa276dcf Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 25 Feb 2023 11:16:55 +0100 Subject: [PATCH] io: add FFI wrappers for io_streams_t fields --- fish-rust/src/builtins/shared.rs | 15 +++++++++++++++ src/io.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/fish-rust/src/builtins/shared.rs b/fish-rust/src/builtins/shared.rs index 7cda69220..33ea233e2 100644 --- a/fish-rust/src/builtins/shared.rs +++ b/fish-rust/src/builtins/shared.rs @@ -4,6 +4,7 @@ use crate::wchar::{wstr, WString, L}; use crate::wchar_ffi::{c_str, empty_wstring, WCharFromFFI}; use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t}; use libc::c_int; +use std::os::fd::RawFd; use std::pin::Pin; #[cxx::bridge] @@ -122,6 +123,20 @@ impl io_streams_t { pub fn ffi_ref(&self) -> &builtins_ffi::io_streams_t { unsafe { &*self.streams } } + + pub fn stdin_is_directly_redirected(&self) -> bool { + self.ffi_ref().ffi_stdin_is_directly_redirected() + } + + pub fn stdin_fd(&self) -> Option { + let ret = self.ffi_ref().ffi_stdin_fd().0; + + if ret < 0 { + None + } else { + Some(ret) + } + } } fn rust_run_builtin( diff --git a/src/io.h b/src/io.h index 8a410a0a1..cf73f2018 100644 --- a/src/io.h +++ b/src/io.h @@ -512,6 +512,8 @@ struct io_streams_t : noncopyable_t { output_stream_t &get_err() { return err; }; io_streams_t(const io_streams_t &) = delete; bool get_out_redirected() { return out_is_redirected; }; + bool ffi_stdin_is_directly_redirected() const { return stdin_is_directly_redirected; }; + int ffi_stdin_fd() const { return stdin_fd; }; }; #endif