Skip to content

Commit eb41d36

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 a60d12c commit eb41d36

File tree

1 file changed

+25
-5
lines changed
  • library/std/src/sys/pal/uefi

1 file changed

+25
-5
lines changed

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

Lines changed: 25 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,37 @@ 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> {
44+
data: crate::os::uefi::ffi::EncodeWide<'a>,
45+
must_yield: bool,
46+
}
4547

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

5052
impl<'a> Iterator for SplitPaths<'a> {
5153
type Item = PathBuf;
54+
5255
fn next(&mut self) -> Option<PathBuf> {
53-
self.0
56+
let must_yield = self.must_yield;
57+
self.must_yield = false;
58+
59+
let mut in_progress = Vec::new();
60+
for b in self.data.by_ref() {
61+
if b == PATHS_SEP {
62+
self.must_yield = true;
63+
break;
64+
} else {
65+
in_progress.push(b)
66+
}
67+
}
68+
69+
if !must_yield && in_progress.is_empty() {
70+
None
71+
} else {
72+
Some(PathBuf::from(OsString::from_wide(&in_progress)))
73+
}
5474
}
5575
}
5676

0 commit comments

Comments
 (0)