Use UTF-8 for all paths

This commit is contained in:
Jeremy Soller
2021-02-14 13:45:03 -07:00
parent 11b5e2fe59
commit 6db78cce24
27 changed files with 207 additions and 183 deletions
+8 -1
View File
@@ -1,4 +1,4 @@
use core::{mem, slice};
use core::{mem, slice, str};
use crate::paging::{ActivePageTable, Page, VirtualAddress};
use crate::paging::entry::EntryFlags;
@@ -48,3 +48,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))
}