Replace all CStr usage to Utf8CStr

This commit is contained in:
topjohnwu
2023-06-12 05:59:50 -07:00
parent caae932117
commit cb3ab63815
7 changed files with 97 additions and 62 deletions

View File

@@ -155,8 +155,8 @@ impl Cpio {
pub(crate) fn load_from_file(path: &Utf8CStr) -> anyhow::Result<Self> {
eprintln!("Loading cpio: [{}]", path);
let data = MappedFile::open(path.as_ref())?;
Self::load_from_data(data.as_ref())
let file = MappedFile::open(path)?;
Self::load_from_data(file.as_ref())
}
fn dump(&self, path: &str) -> anyhow::Result<()> {

View File

@@ -7,7 +7,7 @@ use byteorder::{BigEndian, ReadBytesExt};
use protobuf::{EnumFull, Message};
use base::libc::c_char;
use base::{ptr_to_str_result, ReadSeekExt, StrErr};
use base::{ReadSeekExt, StrErr, Utf8CStr};
use base::{ResultExt, WriteExt};
use crate::ffi;
@@ -26,9 +26,9 @@ macro_rules! bad_payload {
const PAYLOAD_MAGIC: &str = "CrAU";
fn do_extract_boot_from_payload(
in_path: &str,
partition_name: Option<&str>,
out_path: Option<&str>,
in_path: &Utf8CStr,
partition_name: Option<&Utf8CStr>,
out_path: Option<&Utf8CStr>,
) -> anyhow::Result<()> {
let mut reader = BufReader::new(if in_path == "-" {
unsafe { File::from_raw_fd(0) }
@@ -193,13 +193,13 @@ pub fn extract_boot_from_payload(
partition: *const c_char,
out_path: *const c_char,
) -> anyhow::Result<()> {
let in_path = ptr_to_str_result(in_path)?;
let partition = match ptr_to_str_result(partition) {
let in_path = unsafe { Utf8CStr::from_ptr(in_path) }?;
let partition = match unsafe { Utf8CStr::from_ptr(partition) } {
Ok(s) => Some(s),
Err(StrErr::NullPointerError) => None,
Err(e) => Err(e)?,
};
let out_path = match ptr_to_str_result(out_path) {
let out_path = match unsafe { Utf8CStr::from_ptr(out_path) } {
Ok(s) => Some(s),
Err(StrErr::NullPointerError) => None,
Err(e) => Err(e)?,