]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/cloudabi/os.rs
Rollup merge of #78332 - PoignardAzur:doc_E0308, r=camelid
[rust.git] / library / std / src / 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()).unwrap().to_owned()
22 }
23
24 pub fn exit(code: i32) -> ! {
25     unsafe { libc::exit(code as c_int) }
26 }