]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/wasm/os.rs
Rollup merge of #58802 - nnethercote:inline-record_layout, r=oli-obk
[rust.git] / src / libstd / sys / wasm / os.rs
1 use crate::error::Error as StdError;
2 use crate::ffi::{OsString, OsStr};
3 use crate::fmt;
4 use crate::io;
5 use crate::path::{self, PathBuf};
6 use crate::str;
7 use crate::sys::{unsupported, Void, ExitSysCall, GetEnvSysCall, SetEnvSysCall};
8
9 pub fn errno() -> i32 {
10     0
11 }
12
13 pub fn error_string(_errno: i32) -> String {
14     "operation successful".to_string()
15 }
16
17 pub fn getcwd() -> io::Result<PathBuf> {
18     unsupported()
19 }
20
21 pub fn chdir(_: &path::Path) -> io::Result<()> {
22     unsupported()
23 }
24
25 pub struct SplitPaths<'a>(&'a Void);
26
27 pub fn split_paths(_unparsed: &OsStr) -> SplitPaths {
28     panic!("unsupported")
29 }
30
31 impl<'a> Iterator for SplitPaths<'a> {
32     type Item = PathBuf;
33     fn next(&mut self) -> Option<PathBuf> {
34         match *self.0 {}
35     }
36 }
37
38 #[derive(Debug)]
39 pub struct JoinPathsError;
40
41 pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
42     where I: Iterator<Item=T>, T: AsRef<OsStr>
43 {
44     Err(JoinPathsError)
45 }
46
47 impl fmt::Display for JoinPathsError {
48     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49         "not supported on wasm yet".fmt(f)
50     }
51 }
52
53 impl StdError for JoinPathsError {
54     fn description(&self) -> &str {
55         "not supported on wasm yet"
56     }
57 }
58
59 pub fn current_exe() -> io::Result<PathBuf> {
60     unsupported()
61 }
62
63 pub struct Env(Void);
64
65 impl Iterator for Env {
66     type Item = (OsString, OsString);
67     fn next(&mut self) -> Option<(OsString, OsString)> {
68         match self.0 {}
69     }
70 }
71
72 pub fn env() -> Env {
73     panic!("not supported on web assembly")
74 }
75
76 pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
77     Ok(GetEnvSysCall::perform(k))
78 }
79
80 pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
81     Ok(SetEnvSysCall::perform(k, Some(v)))
82 }
83
84 pub fn unsetenv(k: &OsStr) -> io::Result<()> {
85     Ok(SetEnvSysCall::perform(k, None))
86 }
87
88 pub fn temp_dir() -> PathBuf {
89     panic!("no filesystem on wasm")
90 }
91
92 pub fn home_dir() -> Option<PathBuf> {
93     None
94 }
95
96 pub fn exit(_code: i32) -> ! {
97     ExitSysCall::perform(_code as isize as usize)
98 }
99
100 pub fn getpid() -> u32 {
101     panic!("no pids on wasm")
102 }