Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions library/std/src/sys/pal/uefi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use r_efi::efi::protocols::{device_path, loaded_image_device_path};

use super::{helpers, unsupported_err};
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
use crate::path::{self, PathBuf};
use crate::{fmt, io};
Expand Down Expand Up @@ -38,16 +37,37 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
}

pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub struct SplitPaths<'a> {
data: crate::os::uefi::ffi::EncodeWide<'a>,
must_yield: bool,
}

pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
pub fn split_paths(unparsed: &OsStr) -> SplitPaths<'_> {
SplitPaths { data: unparsed.encode_wide(), must_yield: true }
}

impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;

fn next(&mut self) -> Option<PathBuf> {
self.0
let must_yield = self.must_yield;
self.must_yield = false;

let mut in_progress = Vec::new();
for b in self.data.by_ref() {
if b == PATHS_SEP {
self.must_yield = true;
break;
} else {
in_progress.push(b)
}
}

if !must_yield && in_progress.is_empty() {
None
} else {
Some(PathBuf::from(OsString::from_wide(&in_progress)))
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions library/std/tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ fn split_paths_unix() {
assert!(check_parse("/:/usr/local", &mut ["/", "/usr/local"]));
}

#[test]
#[cfg(target_os = "uefi")]
fn split_paths_uefi() {
use std::path::PathBuf;

fn check_parse(unparsed: &str, parsed: &[&str]) -> bool {
split_paths(unparsed).collect::<Vec<_>>()
== parsed.iter().map(|s| PathBuf::from(*s)).collect::<Vec<_>>()
}

assert!(check_parse("", &mut [""]));
assert!(check_parse(";;", &mut ["", "", ""]));
assert!(check_parse(r"fs0:\", &mut [r"fs0:\"]));
assert!(check_parse(r"fs0:\;", &mut [r"fs0:\", ""]));
assert!(check_parse(r"fs0:\;fs0:\boot\", &mut [r"fs0:\", r"fs0:\boot\"]));
}

#[test]
#[cfg(unix)]
fn join_paths_unix() {
Expand Down
Loading