1#![no_std]
2#![cfg_attr(target_os = "none", feature(pattern))]
3#![cfg_attr(target_os = "none", feature(negative_impls))]
4#![cfg_attr(target_os = "none", feature(alloc_io))]
5#![cfg_attr(target_os = "none", feature(core_io))]
6#![cfg_attr(target_os = "none", feature(io_error_uncategorized))]
7#![cfg_attr(target_os = "none", feature(io_error_input_output_error))]
8#![cfg_attr(target_os = "none", feature(io_error_more))]
9#![cfg_attr(target_os = "none", feature(io_error_too_many_open_files))]
10
11extern crate alloc;
12
13#[cfg(not(target_os = "none"))]
14extern crate std;
15
16#[cfg(target_os = "none")]
17pub mod fs;
18#[cfg(target_os = "none")]
19pub mod io;
20#[cfg(target_os = "none")]
21pub mod process;
22#[cfg(target_os = "none")]
23pub mod thread;
24#[cfg(target_os = "none")]
25pub mod os;
26#[cfg(target_os = "none")]
27pub mod sync;
28#[cfg(target_os = "none")]
29pub mod env;
30#[cfg(target_os = "none")]
31pub mod time;
32#[cfg(target_os = "none")]
33pub mod path;
34#[cfg(target_os = "none")]
35pub mod ffi;
36#[cfg(target_os = "none")]
37mod macros;
38#[cfg(target_os = "none")]
39mod panic;
40#[cfg(target_os = "none")]
41mod allocator;
42#[cfg(target_os = "none")]
43pub(crate) mod pagevec;
44#[cfg(target_os = "none")]
45pub mod start;
46#[cfg(not(target_os = "none"))]
47mod start;
48
49use core::mem::MaybeUninit;
50use core::ptr::slice_from_raw_parts_mut;
51#[cfg(not(target_os = "none"))]
52pub use std::fs;
53#[cfg(not(target_os = "none"))]
54pub use std::io;
55#[cfg(not(target_os = "none"))]
56pub use std::process;
57#[cfg(not(target_os = "none"))]
58pub use std::thread;
59#[cfg(not(target_os = "none"))]
60pub use std::os;
61#[cfg(not(target_os = "none"))]
62pub use std::sync;
63#[cfg(not(target_os = "none"))]
64pub use std::env;
65#[cfg(not(target_os = "none"))]
66pub use std::time;
67#[cfg(not(target_os = "none"))]
68pub use std::path;
69#[cfg(not(target_os = "none"))]
70pub use std::ffi;
71#[cfg(not(target_os = "none"))]
72pub use std::{print, println, eprintln, eprint};
73
74use crate::fs::File;
75
76fn read_value<T>(file: &mut File) -> Result<T, io::Error> {
77 use alloc::vec;
78 use crate::io::Read;
79
80 let mut bytes = vec![0; size_of::<T>()];
81 file.read_exact(&mut bytes)?;
82
83 unsafe {
84 let mut value: MaybeUninit<T> = MaybeUninit::uninit();
85
86 let slice = slice_from_raw_parts_mut(&mut value as *mut MaybeUninit<T> as *mut u8, size_of::<T>()).as_mut_unchecked();
87 slice.copy_from_slice(bytes.as_slice());
88
89 Ok(value.assume_init())
90 }
91}
92