gio/
subprocess_launcher.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[cfg(any(unix, all(docsrs, unix)))]
4use std::os::unix::io::{AsFd, AsRawFd, IntoRawFd, OwnedFd};
5
6use glib::translate::*;
7
8use crate::ffi;
9use crate::SubprocessLauncher;
10
11#[cfg(all(docsrs, not(unix)))]
12pub trait IntoRawFd: Sized {
13    fn into_raw_fd(self) -> i32 {
14        0
15    }
16}
17
18impl SubprocessLauncher {
19    #[doc(alias = "g_subprocess_launcher_set_environ")]
20    pub fn set_environ(&self, env: &[std::ffi::OsString]) {
21        unsafe {
22            ffi::g_subprocess_launcher_set_environ(self.to_glib_none().0, env.to_glib_none().0);
23        }
24    }
25
26    #[cfg(unix)]
27    #[cfg_attr(docsrs, doc(cfg(unix)))]
28    #[doc(alias = "g_subprocess_launcher_take_fd")]
29    pub fn take_fd(&self, source_fd: OwnedFd, target_fd: impl AsFd) {
30        let source_raw_fd = source_fd.into_raw_fd();
31        let target_raw_fd = target_fd.as_fd().as_raw_fd();
32        unsafe {
33            ffi::g_subprocess_launcher_take_fd(self.to_glib_none().0, source_raw_fd, target_raw_fd);
34        }
35    }
36
37    #[cfg(unix)]
38    #[cfg_attr(docsrs, doc(cfg(unix)))]
39    #[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
40    pub fn take_stderr_fd(&self, fd: Option<OwnedFd>) {
41        unsafe {
42            let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
43            ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, raw_fd);
44        }
45    }
46
47    #[cfg(unix)]
48    #[cfg_attr(docsrs, doc(cfg(unix)))]
49    #[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
50    pub fn take_stdin_fd(&self, fd: Option<OwnedFd>) {
51        let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
52        unsafe {
53            ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, raw_fd);
54        }
55    }
56
57    #[cfg(unix)]
58    #[cfg_attr(docsrs, doc(cfg(unix)))]
59    #[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
60    pub fn take_stdout_fd(&self, fd: Option<OwnedFd>) {
61        let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
62        unsafe {
63            ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, raw_fd);
64        }
65    }
66}