Skip to content

Commit e50d7bb

Browse files
committed
std: sys: uefi: os: Implement join_paths
- PATHS_SEP is defined as global const since I will implement split_paths in the future. - Tested using OVMF using QEMU. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
1 parent 840245e commit e50d7bb

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

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

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use super::{helpers, unsupported_err};
55
use crate::ffi::{OsStr, OsString};
66
use crate::marker::PhantomData;
77
use crate::os::uefi;
8+
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
89
use crate::path::{self, PathBuf};
910
use crate::ptr::NonNull;
1011
use crate::{fmt, io};
1112

13+
const PATHS_SEP: u16 = b';' as u16;
14+
1215
pub fn errno() -> io::RawOsError {
1316
0
1417
}
@@ -107,12 +110,33 @@ impl<'a> Iterator for SplitPaths<'a> {
107110
#[derive(Debug)]
108111
pub struct JoinPathsError;
109112

110-
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
113+
// UEFI Shell Path variable is defined in Section 3.6.1
114+
// [UEFI Shell Specification](https://uefi.org/sites/default/files/resources/UEFI_Shell_2_2.pdf).
115+
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
111116
where
112117
I: Iterator<Item = T>,
113118
T: AsRef<OsStr>,
114119
{
115-
Err(JoinPathsError)
120+
let mut joined = Vec::new();
121+
122+
for (i, path) in paths.enumerate() {
123+
let path = path.as_ref();
124+
if i > 0 {
125+
joined.push(PATHS_SEP)
126+
}
127+
let v = path.encode_wide().collect::<Vec<u16>>();
128+
if v.contains(&(b'"' as u16)) {
129+
return Err(JoinPathsError);
130+
} else if v.contains(&PATHS_SEP) {
131+
joined.push(b'"' as u16);
132+
joined.extend_from_slice(&v[..]);
133+
joined.push(b'"' as u16);
134+
} else {
135+
joined.extend_from_slice(&v[..]);
136+
}
137+
}
138+
139+
Ok(OsString::from_wide(&joined[..]))
116140
}
117141

118142
impl fmt::Display for JoinPathsError {

0 commit comments

Comments
 (0)