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