@@ -22,14 +22,9 @@ pub struct Shell {
22
22
environment : * const * const CStr16 ,
23
23
out_status : * mut Status ,
24
24
) -> Status ,
25
- get_env : extern "efiapi" fn (
26
- name : * const Char16 ,
27
- ) -> * const Char16 ,
28
- set_env : extern "efiapi" fn (
29
- name : * const Char16 ,
30
- value : * const Char16 ,
31
- volatile : bool ,
32
- ) -> Status ,
25
+ get_env : extern "efiapi" fn ( name : * const Char16 ) -> * const Char16 ,
26
+ set_env :
27
+ extern "efiapi" fn ( name : * const Char16 , value : * const Char16 , volatile : bool ) -> Status ,
33
28
get_alias : usize ,
34
29
set_alias : usize ,
35
30
get_help_text : usize ,
@@ -76,10 +71,7 @@ pub struct Shell {
76
71
file_dir_handle : ShellFileHandle ,
77
72
out_file_list : * mut * mut ShellFileInfo ,
78
73
) -> Status ,
79
- get_file_size : extern "efiapi" fn (
80
- file_handle : ShellFileHandle ,
81
- size : * mut u64
82
- ) -> Status ,
74
+ get_file_size : extern "efiapi" fn ( file_handle : ShellFileHandle , size : * mut u64 ) -> Status ,
83
75
84
76
open_root : usize ,
85
77
open_root_by_handle : usize ,
@@ -164,6 +156,7 @@ impl Shell {
164
156
/// # Returns
165
157
///
166
158
/// * `Some(env_value)` - Value of the environment variable
159
+ /// * `Some(Vec<env_names>)` - Vector of environment variable names
167
160
/// * `None` - Environment variable doesn't exist
168
161
pub fn get_env < ' a > ( & ' a self , name : Option < & CStr16 > ) -> Option < EnvOutput < ' a > > {
169
162
match name {
@@ -178,7 +171,7 @@ impl Shell {
178
171
}
179
172
None => {
180
173
let mut env_vec = Vec :: new ( ) ;
181
- let cur_env_ptr = ( self . get_env ) ( core :: ptr:: null ( ) ) ;
174
+ let cur_env_ptr = ( self . get_env ) ( ptr:: null ( ) ) ;
182
175
183
176
let mut cur_start = cur_env_ptr;
184
177
let mut cur_len = 0 ;
@@ -189,14 +182,13 @@ impl Shell {
189
182
while null_count <= 1 {
190
183
if ( * ( cur_env_ptr. add ( i) ) ) == Char16 :: from_u16_unchecked ( 0 ) {
191
184
if cur_len > 0 {
192
- // TODO: Optimize this to directly convert a
193
- // Char16 slice to CStr16
194
- env_vec . push ( CStr16 :: from_ptr ( cur_start ) ) ;
185
+ env_vec . push ( CStr16 :: from_char16_with_nul_unchecked (
186
+ & ( * ptr :: slice_from_raw_parts ( cur_start , cur_len + 1 ) ) ,
187
+ ) ) ;
195
188
}
196
189
cur_len = 0 ;
197
190
null_count += 1 ;
198
- }
199
- else {
191
+ } else {
200
192
if null_count > 0 {
201
193
cur_start = cur_env_ptr. add ( i) ;
202
194
}
@@ -274,22 +266,17 @@ impl Shell {
274
266
/// * `file_attribs` - Attributes of the new file
275
267
/// * `file_handle` - On return, points to the created file/directory's
276
268
/// handle
277
- pub fn create_file (
278
- & self ,
279
- file_name : & CStr16 ,
280
- file_attribs : u64 ,
281
- ) -> Result < ShellFileHandle > {
269
+ pub fn create_file ( & self , file_name : & CStr16 , file_attribs : u64 ) -> Result < ShellFileHandle > {
282
270
// TODO: Find out how we could take a &str instead, or maybe AsRef<str>, though I think it needs `alloc`
283
271
// the returned handle can possibly be NULL, so we need to wrap `ShellFileHandle` in an `Option`
284
272
//let mut out_file_handle: MaybeUninit<Option<ShellFileHandle>> = MaybeUninit::zeroed();
285
273
// let mut file_handle: ShellFileHandle;
286
274
let file_handle = ptr:: null ( ) ;
287
275
288
- ( self . create_file ) ( file_name, file_attribs, file_handle)
289
- . to_result_with_val ( || file_handle )
290
- // Safety: if this call is successful, `out_file_handle`
291
- // will always be initialized and valid.
292
- // .to_result_with_val(|| unsafe { out_file_handle.assume_init() })
276
+ ( self . create_file ) ( file_name, file_attribs, file_handle) . to_result_with_val ( || file_handle)
277
+ // Safety: if this call is successful, `out_file_handle`
278
+ // will always be initialized and valid.
279
+ // .to_result_with_val(|| unsafe { out_file_handle.assume_init() })
293
280
}
294
281
295
282
/// TODO
0 commit comments