1 // Copyright 2018 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.
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.
11 use fortanix_sgx_abi::{Error, RESULT_SUCCESS};
13 use error::Error as StdError;
14 use ffi::{OsString, OsStr};
17 use path::{self, PathBuf};
19 use sys::{unsupported, Void, sgx_ineffective, decode_error_kind};
21 pub fn errno() -> i32 {
25 pub fn error_string(errno: i32) -> String {
26 if errno == RESULT_SUCCESS {
27 "operation succesful".into()
28 } else if ((Error::UserRangeStart as _)..=(Error::UserRangeEnd as _)).contains(&errno) {
29 format!("user-specified error {:08x}", errno)
31 decode_error_kind(errno).as_str().into()
35 pub fn getcwd() -> io::Result<PathBuf> {
39 pub fn chdir(_: &path::Path) -> io::Result<()> {
43 pub struct SplitPaths<'a>(&'a Void);
45 pub fn split_paths(_unparsed: &OsStr) -> SplitPaths {
49 impl<'a> Iterator for SplitPaths<'a> {
51 fn next(&mut self) -> Option<PathBuf> {
57 pub struct JoinPathsError;
59 pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
60 where I: Iterator<Item=T>, T: AsRef<OsStr>
65 impl fmt::Display for JoinPathsError {
66 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
67 "not supported in SGX yet".fmt(f)
71 impl StdError for JoinPathsError {
72 fn description(&self) -> &str {
73 "not supported in SGX yet"
77 pub fn current_exe() -> io::Result<PathBuf> {
83 impl Iterator for Env {
84 type Item = (OsString, OsString);
85 fn next(&mut self) -> Option<(OsString, OsString)> {
94 pub fn getenv(_k: &OsStr) -> io::Result<Option<OsString>> {
98 pub fn setenv(_k: &OsStr, _v: &OsStr) -> io::Result<()> {
99 sgx_ineffective(()) // FIXME: this could trigger a panic higher up the stack
102 pub fn unsetenv(_k: &OsStr) -> io::Result<()> {
103 sgx_ineffective(()) // FIXME: this could trigger a panic higher up the stack
106 pub fn temp_dir() -> PathBuf {
107 panic!("no filesystem in SGX")
110 pub fn home_dir() -> Option<PathBuf> {
114 pub fn exit(code: i32) -> ! {
115 super::abi::exit_with_code(code as _)
118 pub fn getpid() -> u32 {
119 panic!("no pids in SGX")