Skip to content

Commit 9fe6175

Browse files
committed
std: sys: pal: uefi: os: Implement split_paths
- Based on Windows implementation. Just removed support for quote escaping since that is not supported in UEFI. - Tested using OVMF on QEMU Signed-off-by: Ayush Singh <ayush@beagleboard.org>
1 parent bb779a9 commit 9fe6175

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

  • library/std/src/sys/pal/uefi

library/std/src/sys/pal/uefi/os.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use r_efi::efi::protocols::{device_path, loaded_image_device_path};
22

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

41-
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
40+
pub struct SplitPaths<'a> {
41+
data: crate::os::uefi::ffi::EncodeWide<'a>,
42+
must_yield: bool,
43+
}
4244

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

4749
impl<'a> Iterator for SplitPaths<'a> {
4850
type Item = PathBuf;
51+
4952
fn next(&mut self) -> Option<PathBuf> {
50-
self.0
53+
let must_yield = self.must_yield;
54+
self.must_yield = false;
55+
56+
let mut in_progress = Vec::new();
57+
for b in self.data.by_ref() {
58+
if b == PATHS_SEP {
59+
self.must_yield = true;
60+
break;
61+
} else {
62+
in_progress.push(b)
63+
}
64+
}
65+
66+
if !must_yield && in_progress.is_empty() {
67+
None
68+
} else {
69+
Some(PathBuf::from(OsString::from_wide(&in_progress)))
70+
}
5171
}
5272
}
5373

0 commit comments

Comments
 (0)