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