]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/unsupported/common.rs
Rename ErrorKind::Unknown to Uncategorized.
[rust.git] / library / std / src / sys / unsupported / common.rs
1 use crate::io as std_io;
2
3 pub mod memchr {
4     pub use core::slice::memchr::{memchr, memrchr};
5 }
6
7 pub use crate::sys_common::os_str_bytes as os_str;
8
9 // This is not necessarily correct. May want to consider making it part of the
10 // spec definition?
11 use crate::os::raw::c_char;
12
13 // SAFETY: must be called only once during runtime initialization.
14 // NOTE: this is not guaranteed to run, for example when Rust code is called externally.
15 pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
16
17 // SAFETY: must be called only once during runtime cleanup.
18 // NOTE: this is not guaranteed to run, for example when the program aborts.
19 pub unsafe fn cleanup() {}
20
21 pub fn unsupported<T>() -> std_io::Result<T> {
22     Err(unsupported_err())
23 }
24
25 pub fn unsupported_err() -> std_io::Error {
26     std_io::Error::new_const(
27         std_io::ErrorKind::Unsupported,
28         &"operation not supported on this platform",
29     )
30 }
31
32 pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind {
33     crate::io::ErrorKind::Uncategorized
34 }
35
36 pub fn abort_internal() -> ! {
37     core::intrinsics::abort();
38 }
39
40 pub fn hashmap_random_keys() -> (u64, u64) {
41     (1, 2)
42 }
43
44 pub unsafe fn strlen(mut s: *const c_char) -> usize {
45     // SAFETY: The caller must guarantee `s` points to a valid 0-terminated string.
46     unsafe {
47         let mut n = 0;
48         while *s != 0 {
49             n += 1;
50             s = s.offset(1);
51         }
52         n
53     }
54 }