mirror of
https://github.com/NotAShelf/microfetch.git
synced 2026-04-13 13:23:52 +00:00
treewide: going no_std
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ia1c001eb099ea8cae9bdf76642b873376a6a6964
This commit is contained in:
parent
1b0e3070bb
commit
472dbfc7e7
14 changed files with 856 additions and 143 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use std::{io, mem::MaybeUninit};
|
||||
use alloc::string::String;
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
use crate::syscall::sys_sysinfo;
|
||||
use crate::{Error, syscall::sys_sysinfo};
|
||||
|
||||
/// Faster integer to string conversion without the formatting overhead.
|
||||
#[inline]
|
||||
|
|
@ -16,7 +17,8 @@ fn itoa(mut n: u64, buf: &mut [u8]) -> &str {
|
|||
n /= 10;
|
||||
}
|
||||
|
||||
unsafe { std::str::from_utf8_unchecked(&buf[i..]) }
|
||||
// SAFETY: We only wrote ASCII digits
|
||||
unsafe { core::str::from_utf8_unchecked(&buf[i..]) }
|
||||
}
|
||||
|
||||
/// Gets the current system uptime.
|
||||
|
|
@ -25,11 +27,11 @@ fn itoa(mut n: u64, buf: &mut [u8]) -> &str {
|
|||
///
|
||||
/// Returns an error if the system uptime cannot be retrieved.
|
||||
#[cfg_attr(feature = "hotpath", hotpath::measure)]
|
||||
pub fn get_current() -> Result<String, io::Error> {
|
||||
pub fn get_current() -> Result<String, Error> {
|
||||
let uptime_seconds = {
|
||||
let mut info = MaybeUninit::uninit();
|
||||
if unsafe { sys_sysinfo(info.as_mut_ptr()) } != 0 {
|
||||
return Err(io::Error::last_os_error());
|
||||
return Err(Error::last_os_error());
|
||||
}
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
unsafe {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue