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