Skip to content

Commit 36e28a4

Browse files
committed
Implemented set_env()
1 parent 647067d commit 36e28a4

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

uefi-test-runner/src/proto/shell.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,31 @@ pub fn test() {
1919
let cur_env_str = shell.get_env(None).expect("Could not get environment variable");
2020
info!("cur_env_str size: {}", cur_env_str.num_chars());
2121
info!("cur_env_str: {}", cur_env_str);
22+
23+
/* Testing setting and getting a specific environment variable */
24+
let mut test_env_buf = [0u16; 32];
25+
let test_var = CStr16::from_str_with_buf("test_var", &mut test_env_buf).unwrap();
26+
let mut test_val_buf = [0u16; 32];
27+
let test_val = CStr16::from_str_with_buf("test_val", &mut test_val_buf).unwrap();
28+
assert!(shell.get_env(Some(test_var)).is_none());
29+
shell.set_env(test_var, test_val, false);
30+
let cur_env_str = shell.get_env(Some(test_var)).expect("Could not get environment variable");
31+
assert_eq!(cur_env_str, test_val);
32+
2233
// for (i, c) in cur_env_str.iter().enumerate() {
2334
// info!("cur_env_str: i: {}, c: {}", i, c);
2435
// }
2536

2637
// let mut cur_fs_buf = [0u16; 32];
2738
// let cur_fs_str = CStr16::from_str_with_buf("", &mut cur_fs_buf).unwrap();
2839
// info!("cur_fs_str size 1: {}", cur_fs_str.num_chars());
29-
let cur_fs_str = shell.get_cur_dir(None).expect("Could not get the current file system mapping");
30-
info!("cur_fs_str size: {}", cur_fs_str.num_chars());
31-
info!("cur_fs_str: {}", cur_fs_str);
40+
41+
42+
// let cur_fs_str = shell.get_cur_dir(None).expect("Could not get the current file system mapping");
43+
// info!("cur_fs_str size: {}", cur_fs_str.num_chars());
44+
// info!("cur_fs_str: {}", cur_fs_str);
45+
46+
3247
// for (i, c) in cur_fs_str.iter().enumerate() {
3348
// info!("cur_fs_str: i: {}, c: {}", i, c);
3449
// }

uefi/src/proto/shell/mod.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ pub struct Shell {
2121
get_env: extern "efiapi" fn(
2222
name: *const Char16,
2323
) -> *const Char16,
24-
set_env: usize,
24+
set_env: extern "efiapi" fn(
25+
name: *const Char16,
26+
value: *const Char16,
27+
volatile: bool,
28+
) -> Status,
2529
get_alias: usize,
2630
set_alias: usize,
2731
get_help_text: usize,
@@ -137,6 +141,24 @@ impl Shell {
137141
}
138142
}
139143

144+
/// Sets the environment variable
145+
///
146+
/// # Arguments
147+
///
148+
/// * `name` - The environment variable for which to set the value
149+
/// * `value` - The new value of the environment variable
150+
/// * `volatile` - Indicates whether or not the variable is volatile or
151+
/// not
152+
///
153+
/// # Returns
154+
///
155+
/// * `Status::SUCCESS` The variable was successfully set
156+
pub fn set_env(&self, name: &CStr16, value: &CStr16, volatile: bool) -> Status {
157+
let name_ptr: *const Char16 = (name as *const CStr16).cast();
158+
let value_ptr: *const Char16 = (value as *const CStr16).cast();
159+
(self.set_env)(name_ptr, value_ptr, volatile)
160+
}
161+
140162
/// TODO
141163
#[must_use]
142164
pub fn get_cur_dir<'a>(&'a self, file_system_mapping: Option<&CStr16>) -> Option<&'a CStr16> {

0 commit comments

Comments
 (0)