Avoid StringWriter cast and string format
This commit is contained in:
+2
-2
@@ -147,13 +147,13 @@ impl Read for FileReader {
|
||||
}
|
||||
|
||||
/// An implementation of [`Write`]/[`core::fmt::Write`] for a byte array.
|
||||
pub struct StringWriter(pub *mut u8, pub usize);
|
||||
pub struct StringWriter(pub *mut c_char, pub usize);
|
||||
impl Write for StringWriter {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
if self.1 > 1 {
|
||||
let copy_size = buf.len().min(self.1 - 1);
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(buf.as_ptr(), self.0, copy_size);
|
||||
ptr::copy_nonoverlapping(buf.as_ptr() as _, self.0, copy_size);
|
||||
self.1 -= copy_size;
|
||||
|
||||
self.0 = self.0.add(copy_size);
|
||||
|
||||
@@ -48,7 +48,9 @@ use crate::{
|
||||
sys_statvfs::statvfs,
|
||||
sys_time::timezone,
|
||||
sys_utsname::{UTSLENGTH, utsname},
|
||||
time::{TIMER_ABSTIME, itimerspec, timer_internal_t, timespec},
|
||||
time::{
|
||||
CLOCK_MONOTONIC, CLOCK_REALTIME, TIMER_ABSTIME, itimerspec, timer_internal_t, timespec,
|
||||
},
|
||||
unistd::{F_OK, R_OK, SEEK_CUR, SEEK_SET, W_OK, X_OK},
|
||||
},
|
||||
io::{self, BufReader, prelude::*},
|
||||
@@ -204,7 +206,11 @@ impl Pal for Sys {
|
||||
}
|
||||
|
||||
fn clock_getres(clk_id: clockid_t, res: Option<Out<timespec>>) -> Result<()> {
|
||||
let path = format!("/scheme/time/{clk_id}/getres");
|
||||
let path = match clk_id {
|
||||
CLOCK_REALTIME => "/scheme/time/1/getres",
|
||||
CLOCK_MONOTONIC => "/scheme/time/4/getres",
|
||||
_ => return Err(Errno(EINVAL)),
|
||||
};
|
||||
let timerfd = FdGuard::open(&path, syscall::O_RDONLY)?;
|
||||
let mut redox_res = timespec::default();
|
||||
let buffer = unsafe {
|
||||
@@ -1231,7 +1237,11 @@ impl Pal for Sys {
|
||||
}
|
||||
}
|
||||
|
||||
let path = format!("/scheme/time/{clock_id}");
|
||||
let path = match clock_id {
|
||||
CLOCK_REALTIME => "/scheme/time/1",
|
||||
CLOCK_MONOTONIC => "/scheme/time/4",
|
||||
_ => return Err(Errno(EINVAL)),
|
||||
};
|
||||
let timerfd = FdGuard::open(&path, syscall::O_RDWR)?.to_upper()?;
|
||||
let eventfd = FdGuard::new(Error::demux(unsafe {
|
||||
event::redox_event_queue_create_v1(0)
|
||||
|
||||
Reference in New Issue
Block a user