]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/cloudabi/os.rs
Auto merge of #56534 - xfix:copied, r=@SimonSapin
[rust.git] / src / libstd / sys / cloudabi / os.rs
1 use ffi::CStr;
2 use libc::{self, c_int};
3 use str;
4
5 pub use sys::cloudabi::shims::os::*;
6
7 pub fn errno() -> i32 {
8     extern "C" {
9         #[thread_local]
10         static errno: c_int;
11     }
12
13     unsafe { errno as i32 }
14 }
15
16 /// Gets a detailed string description for the given error number.
17 pub fn error_string(errno: i32) -> String {
18     // cloudlibc's strerror() is guaranteed to be thread-safe. There is
19     // thus no need to use strerror_r().
20     str::from_utf8(unsafe { CStr::from_ptr(libc::strerror(errno)) }.to_bytes())
21         .unwrap()
22         .to_owned()
23 }
24
25 pub fn exit(code: i32) -> ! {
26     unsafe { libc::exit(code as c_int) }
27 }