]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/wasm/os.rs
Auto merge of #47956 - retep998:is-nibbles, r=BurntSushi
[rust.git] / src / libstd / sys / wasm / os.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use error::Error as StdError;
12 use ffi::{OsString, OsStr};
13 use fmt;
14 use io;
15 use path::{self, PathBuf};
16 use str;
17 use sys::{unsupported, Void, ExitSysCall, GetEnvSysCall, SetEnvSysCall};
18
19 pub fn errno() -> i32 {
20     0
21 }
22
23 pub fn error_string(_errno: i32) -> String {
24     format!("operation successful")
25 }
26
27 pub fn getcwd() -> io::Result<PathBuf> {
28     unsupported()
29 }
30
31 pub fn chdir(_: &path::Path) -> io::Result<()> {
32     unsupported()
33 }
34
35 pub struct SplitPaths<'a>(&'a Void);
36
37 pub fn split_paths(_unparsed: &OsStr) -> SplitPaths {
38     panic!("unsupported")
39 }
40
41 impl<'a> Iterator for SplitPaths<'a> {
42     type Item = PathBuf;
43     fn next(&mut self) -> Option<PathBuf> {
44         match *self.0 {}
45     }
46 }
47
48 #[derive(Debug)]
49 pub struct JoinPathsError;
50
51 pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
52     where I: Iterator<Item=T>, T: AsRef<OsStr>
53 {
54     Err(JoinPathsError)
55 }
56
57 impl fmt::Display for JoinPathsError {
58     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59         "not supported on wasm yet".fmt(f)
60     }
61 }
62
63 impl StdError for JoinPathsError {
64     fn description(&self) -> &str {
65         "not supported on wasm yet"
66     }
67 }
68
69 pub fn current_exe() -> io::Result<PathBuf> {
70     unsupported()
71 }
72
73 pub struct Env(Void);
74
75 impl Iterator for Env {
76     type Item = (OsString, OsString);
77     fn next(&mut self) -> Option<(OsString, OsString)> {
78         match self.0 {}
79     }
80 }
81
82 pub fn env() -> Env {
83     panic!("not supported on web assembly")
84 }
85
86 pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
87     Ok(GetEnvSysCall::perform(k))
88 }
89
90 pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
91     Ok(SetEnvSysCall::perform(k, Some(v)))
92 }
93
94 pub fn unsetenv(k: &OsStr) -> io::Result<()> {
95     Ok(SetEnvSysCall::perform(k, None))
96 }
97
98 pub fn temp_dir() -> PathBuf {
99     panic!("no filesystem on wasm")
100 }
101
102 pub fn home_dir() -> Option<PathBuf> {
103     None
104 }
105
106 pub fn exit(_code: i32) -> ! {
107     ExitSysCall::perform(_code as isize as usize)
108 }
109
110 pub fn getpid() -> u32 {
111     panic!("no pids on wasm")
112 }