Use UTF-8 for all paths

This commit is contained in:
Jeremy Soller
2021-02-14 13:45:03 -07:00
parent 8fcd375bd9
commit d331f72f2a
28 changed files with 217 additions and 193 deletions
+8 -1
View File
@@ -1,4 +1,4 @@
use core::{mem, slice};
use core::{mem, slice, str};
use crate::paging::{ActivePageTable, PageTableType, Page, VirtualAddress, VirtualAddressType};
use crate::paging::entry::EntryFlags;
@@ -51,3 +51,10 @@ pub fn validate_slice_mut<T>(ptr: *mut T, len: usize) -> Result<&'static mut [T]
Ok(unsafe { slice::from_raw_parts_mut(ptr, len) })
}
}
/// Convert a pointer and length to str, if valid
//TODO: Mark unsafe
pub fn validate_str(ptr: *const u8, len: usize) -> Result<&'static str> {
let slice = validate_slice(ptr, len)?;
str::from_utf8(slice).map_err(|_| Error::new(EINVAL))
}