Skip to content

Commit 2ac9b50

Browse files
committed
std: sys: pal: uefi: os: Implement split_paths
- Tested using OVMF on QEMU Signed-off-by: Ayush Singh <ayush@beagleboard.org>
1 parent a60d12c commit 2ac9b50

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

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

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

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

44
use super::{helpers, unsupported_err};
55
use crate::ffi::{OsStr, OsString};
6-
use crate::marker::PhantomData;
76
use crate::os::uefi;
87
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
98
use crate::path::{self, PathBuf};
@@ -41,16 +40,29 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
4140
if r.is_error() { Err(io::Error::from_raw_os_error(r.as_usize())) } else { Ok(()) }
4241
}
4342

44-
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
43+
pub struct SplitPaths<'a>(crate::os::uefi::ffi::EncodeWide<'a>);
4544

46-
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
47-
panic!("unsupported")
45+
pub fn split_paths(unparsed: &OsStr) -> SplitPaths<'_> {
46+
SplitPaths(unparsed.encode_wide())
4847
}
4948

5049
impl<'a> Iterator for SplitPaths<'a> {
5150
type Item = PathBuf;
5251
fn next(&mut self) -> Option<PathBuf> {
53-
self.0
52+
let mut buf = Vec::new();
53+
54+
loop {
55+
match self.0.next() {
56+
// Ignore consecutive sepearators
57+
Some(ch) if ch == PATHS_SEP && buf.is_empty() => {}
58+
Some(ch) if ch == PATHS_SEP => break,
59+
Some(ch) => buf.push(ch),
60+
None if buf.is_empty() => return None,
61+
None => break,
62+
}
63+
}
64+
65+
Some(PathBuf::from(OsString::from_wide(&buf)))
5466
}
5567
}
5668

0 commit comments

Comments
 (0)