]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/unix/process/process_unsupported.rs
Add tests for #41731
[rust.git] / library / std / src / sys / unix / process / process_unsupported.rs
1 use crate::fmt;
2 use crate::io;
3 use crate::num::NonZeroI32;
4 use crate::sys::process::process_common::*;
5 use crate::sys::unix::unsupported::*;
6 use core::ffi::NonZero_c_int;
7
8 use libc::{c_int, pid_t};
9
10 ////////////////////////////////////////////////////////////////////////////////
11 // Command
12 ////////////////////////////////////////////////////////////////////////////////
13
14 impl Command {
15     pub fn spawn(
16         &mut self,
17         _default: Stdio,
18         _needs_stdin: bool,
19     ) -> io::Result<(Process, StdioPipes)> {
20         unsupported()
21     }
22
23     pub fn exec(&mut self, _default: Stdio) -> io::Error {
24         unsupported_err()
25     }
26 }
27
28 ////////////////////////////////////////////////////////////////////////////////
29 // Processes
30 ////////////////////////////////////////////////////////////////////////////////
31
32 pub struct Process {
33     _handle: pid_t,
34 }
35
36 impl Process {
37     pub fn id(&self) -> u32 {
38         0
39     }
40
41     pub fn kill(&mut self) -> io::Result<()> {
42         unsupported()
43     }
44
45     pub fn wait(&mut self) -> io::Result<ExitStatus> {
46         unsupported()
47     }
48
49     pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
50         unsupported()
51     }
52 }
53
54 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
55 pub struct ExitStatus(c_int);
56
57 impl ExitStatus {
58     #[cfg_attr(target_os = "horizon", allow(unused))]
59     pub fn success(&self) -> bool {
60         self.code() == Some(0)
61     }
62
63     pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
64         Err(ExitStatusError(1.try_into().unwrap()))
65     }
66
67     pub fn code(&self) -> Option<i32> {
68         None
69     }
70
71     pub fn signal(&self) -> Option<i32> {
72         None
73     }
74
75     pub fn core_dumped(&self) -> bool {
76         false
77     }
78
79     pub fn stopped_signal(&self) -> Option<i32> {
80         None
81     }
82
83     pub fn continued(&self) -> bool {
84         false
85     }
86
87     pub fn into_raw(&self) -> c_int {
88         0
89     }
90 }
91
92 /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying.
93 impl From<c_int> for ExitStatus {
94     fn from(a: c_int) -> ExitStatus {
95         ExitStatus(a as i32)
96     }
97 }
98
99 impl fmt::Display for ExitStatus {
100     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
101         write!(f, "exit code: {}", self.0)
102     }
103 }
104
105 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
106 pub struct ExitStatusError(NonZero_c_int);
107
108 impl Into<ExitStatus> for ExitStatusError {
109     fn into(self) -> ExitStatus {
110         ExitStatus(self.0.into())
111     }
112 }
113
114 impl ExitStatusError {
115     pub fn code(self) -> Option<NonZeroI32> {
116         ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())
117     }
118 }