| 
 | 1 | +use super::{abi, unsupported, WORD_SIZE};  | 
 | 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::path::{self, PathBuf};  | 
 | 8 | +use crate::sys_common::FromInner;  | 
 | 9 | + | 
 | 10 | +pub fn errno() -> i32 {  | 
 | 11 | +    0  | 
 | 12 | +}  | 
 | 13 | + | 
 | 14 | +pub fn error_string(_errno: i32) -> String {  | 
 | 15 | +    "operation successful".to_string()  | 
 | 16 | +}  | 
 | 17 | + | 
 | 18 | +pub fn getcwd() -> io::Result<PathBuf> {  | 
 | 19 | +    unsupported()  | 
 | 20 | +}  | 
 | 21 | + | 
 | 22 | +pub fn chdir(_: &path::Path) -> io::Result<()> {  | 
 | 23 | +    unsupported()  | 
 | 24 | +}  | 
 | 25 | + | 
 | 26 | +pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);  | 
 | 27 | + | 
 | 28 | +pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {  | 
 | 29 | +    panic!("unsupported")  | 
 | 30 | +}  | 
 | 31 | + | 
 | 32 | +impl<'a> Iterator for SplitPaths<'a> {  | 
 | 33 | +    type Item = PathBuf;  | 
 | 34 | +    fn next(&mut self) -> Option<PathBuf> {  | 
 | 35 | +        self.0  | 
 | 36 | +    }  | 
 | 37 | +}  | 
 | 38 | + | 
 | 39 | +#[derive(Debug)]  | 
 | 40 | +pub struct JoinPathsError;  | 
 | 41 | + | 
 | 42 | +pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>  | 
 | 43 | +where  | 
 | 44 | +    I: Iterator<Item = T>,  | 
 | 45 | +    T: AsRef<OsStr>,  | 
 | 46 | +{  | 
 | 47 | +    Err(JoinPathsError)  | 
 | 48 | +}  | 
 | 49 | + | 
 | 50 | +impl fmt::Display for JoinPathsError {  | 
 | 51 | +    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {  | 
 | 52 | +        "not supported on this platform yet".fmt(f)  | 
 | 53 | +    }  | 
 | 54 | +}  | 
 | 55 | + | 
 | 56 | +impl StdError for JoinPathsError {  | 
 | 57 | +    #[allow(deprecated)]  | 
 | 58 | +    fn description(&self) -> &str {  | 
 | 59 | +        "not supported on this platform yet"  | 
 | 60 | +    }  | 
 | 61 | +}  | 
 | 62 | + | 
 | 63 | +pub fn current_exe() -> io::Result<PathBuf> {  | 
 | 64 | +    unsupported()  | 
 | 65 | +}  | 
 | 66 | + | 
 | 67 | +pub struct Env(!);  | 
 | 68 | + | 
 | 69 | +impl Iterator for Env {  | 
 | 70 | +    type Item = (OsString, OsString);  | 
 | 71 | +    fn next(&mut self) -> Option<(OsString, OsString)> {  | 
 | 72 | +        self.0  | 
 | 73 | +    }  | 
 | 74 | +}  | 
 | 75 | + | 
 | 76 | +pub fn env() -> Env {  | 
 | 77 | +    panic!("not supported on this platform")  | 
 | 78 | +}  | 
 | 79 | + | 
 | 80 | +pub fn getenv(varname: &OsStr) -> Option<OsString> {  | 
 | 81 | +    let varname = varname.bytes();  | 
 | 82 | +    let nbytes =  | 
 | 83 | +        unsafe { abi::sys_getenv(crate::ptr::null_mut(), 0, varname.as_ptr(), varname.len()) };  | 
 | 84 | +    if nbytes == usize::MAX {  | 
 | 85 | +        return None;  | 
 | 86 | +    }  | 
 | 87 | + | 
 | 88 | +    let nwords = (nbytes + WORD_SIZE - 1) / WORD_SIZE;  | 
 | 89 | +    let words = unsafe { abi::sys_alloc_words(nwords) };  | 
 | 90 | + | 
 | 91 | +    let nbytes2 = unsafe { abi::sys_getenv(words, nwords, varname.as_ptr(), varname.len()) };  | 
 | 92 | +    debug_assert_eq!(nbytes, nbytes2);  | 
 | 93 | + | 
 | 94 | +    // Convert to OsString.  | 
 | 95 | +    //  | 
 | 96 | +    // FIXME: We can probably get rid of the extra copy here if we  | 
 | 97 | +    // reimplement "os_str" instead of just using the generic unix  | 
 | 98 | +    // "os_str".  | 
 | 99 | +    let u8s: &[u8] = unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, nbytes) };  | 
 | 100 | +    Some(OsString::from_inner(super::os_str::Buf { inner: u8s.to_vec() }))  | 
 | 101 | +}  | 
 | 102 | + | 
 | 103 | +pub fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {  | 
 | 104 | +    Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))  | 
 | 105 | +}  | 
 | 106 | + | 
 | 107 | +pub fn unsetenv(_: &OsStr) -> io::Result<()> {  | 
 | 108 | +    Err(io::const_io_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))  | 
 | 109 | +}  | 
 | 110 | + | 
 | 111 | +pub fn temp_dir() -> PathBuf {  | 
 | 112 | +    panic!("no filesystem on this platform")  | 
 | 113 | +}  | 
 | 114 | + | 
 | 115 | +pub fn home_dir() -> Option<PathBuf> {  | 
 | 116 | +    None  | 
 | 117 | +}  | 
 | 118 | + | 
 | 119 | +pub fn exit(_code: i32) -> ! {  | 
 | 120 | +    crate::intrinsics::abort()  | 
 | 121 | +}  | 
 | 122 | + | 
 | 123 | +pub fn getpid() -> u32 {  | 
 | 124 | +    panic!("no pids on this platform")  | 
 | 125 | +}  | 
0 commit comments