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