|
| 1 | +use super::unsupported; |
| 2 | +use crate::error::Error as StdError; |
| 3 | +use crate::ffi::{OsStr, OsString}; |
| 4 | +use crate::fmt; |
| 5 | +use crate::io; |
| 6 | +use crate::marker::PhantomData; |
| 7 | +use crate::os::xous::ffi::Error as XousError; |
| 8 | +use crate::path::{self, PathBuf}; |
| 9 | + |
| 10 | +#[cfg(not(test))] |
| 11 | +mod c_compat { |
| 12 | + use crate::os::xous::ffi::exit; |
| 13 | + extern "C" { |
| 14 | + fn main() -> u32; |
| 15 | + } |
| 16 | + |
| 17 | + #[no_mangle] |
| 18 | + pub extern "C" fn abort() { |
| 19 | + exit(1); |
| 20 | + } |
| 21 | + |
| 22 | + #[no_mangle] |
| 23 | + pub extern "C" fn _start() { |
| 24 | + exit(unsafe { main() }); |
| 25 | + } |
| 26 | + |
| 27 | + // This function is needed by the panic runtime. The symbol is named in |
| 28 | + // pre-link args for the target specification, so keep that in sync. |
| 29 | + #[no_mangle] |
| 30 | + // NB. used by both libunwind and libpanic_abort |
| 31 | + pub extern "C" fn __rust_abort() -> ! { |
| 32 | + exit(101); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +pub fn errno() -> i32 { |
| 37 | + 0 |
| 38 | +} |
| 39 | + |
| 40 | +pub fn error_string(errno: i32) -> String { |
| 41 | + Into::<XousError>::into(errno).to_string() |
| 42 | +} |
| 43 | + |
| 44 | +pub fn getcwd() -> io::Result<PathBuf> { |
| 45 | + unsupported() |
| 46 | +} |
| 47 | + |
| 48 | +pub fn chdir(_: &path::Path) -> io::Result<()> { |
| 49 | + unsupported() |
| 50 | +} |
| 51 | + |
| 52 | +pub struct SplitPaths<'a>(!, PhantomData<&'a ()>); |
| 53 | + |
| 54 | +pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> { |
| 55 | + panic!("unsupported") |
| 56 | +} |
| 57 | + |
| 58 | +impl<'a> Iterator for SplitPaths<'a> { |
| 59 | + type Item = PathBuf; |
| 60 | + fn next(&mut self) -> Option<PathBuf> { |
| 61 | + self.0 |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +#[derive(Debug)] |
| 66 | +pub struct JoinPathsError; |
| 67 | + |
| 68 | +pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError> |
| 69 | +where |
| 70 | + I: Iterator<Item = T>, |
| 71 | + T: AsRef<OsStr>, |
| 72 | +{ |
| 73 | + Err(JoinPathsError) |
| 74 | +} |
| 75 | + |
| 76 | +impl fmt::Display for JoinPathsError { |
| 77 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 78 | + "not supported on this platform yet".fmt(f) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +impl StdError for JoinPathsError { |
| 83 | + #[allow(deprecated)] |
| 84 | + fn description(&self) -> &str { |
| 85 | + "not supported on this platform yet" |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +pub fn current_exe() -> io::Result<PathBuf> { |
| 90 | + unsupported() |
| 91 | +} |
| 92 | + |
| 93 | +pub struct Env(!); |
| 94 | + |
| 95 | +impl Env { |
| 96 | + // FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt. |
| 97 | + pub fn str_debug(&self) -> impl fmt::Debug + '_ { |
| 98 | + let Self(inner) = self; |
| 99 | + match *inner {} |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +impl fmt::Debug for Env { |
| 104 | + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 105 | + let Self(inner) = self; |
| 106 | + match *inner {} |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +impl Iterator for Env { |
| 111 | + type Item = (OsString, OsString); |
| 112 | + fn next(&mut self) -> Option<(OsString, OsString)> { |
| 113 | + self.0 |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +pub fn env() -> Env { |
| 118 | + panic!("not supported on this platform") |
| 119 | +} |
| 120 | + |
| 121 | +pub fn getenv(_: &OsStr) -> Option<OsString> { |
| 122 | + None |
| 123 | +} |
| 124 | + |
| 125 | +pub fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> { |
| 126 | + Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform")) |
| 127 | +} |
| 128 | + |
| 129 | +pub fn unsetenv(_: &OsStr) -> io::Result<()> { |
| 130 | + Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform")) |
| 131 | +} |
| 132 | + |
| 133 | +pub fn temp_dir() -> PathBuf { |
| 134 | + panic!("no filesystem on this platform") |
| 135 | +} |
| 136 | + |
| 137 | +pub fn home_dir() -> Option<PathBuf> { |
| 138 | + None |
| 139 | +} |
| 140 | + |
| 141 | +pub fn exit(code: i32) -> ! { |
| 142 | + crate::os::xous::ffi::exit(code as u32); |
| 143 | +} |
| 144 | + |
| 145 | +pub fn getpid() -> u32 { |
| 146 | + panic!("no pids on this platform") |
| 147 | +} |
0 commit comments