io: add FFI wrappers for io_streams_t fields

This commit is contained in:
Xiretza 2023-02-25 11:16:55 +01:00 committed by Johannes Altmanninger
parent ba5e1dfb69
commit cc744d30c0
2 changed files with 17 additions and 0 deletions

View File

@ -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<RawFd> {
let ret = self.ffi_ref().ffi_stdin_fd().0;
if ret < 0 {
None
} else {
Some(ret)
}
}
}
fn rust_run_builtin(

View File

@ -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