@@ -22,14 +22,9 @@ pub struct Shell {
2222 environment : * const * const CStr16 ,
2323 out_status : * mut Status ,
2424 ) -> 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 ,
3328 get_alias : usize ,
3429 set_alias : usize ,
3530 get_help_text : usize ,
@@ -76,10 +71,7 @@ pub struct Shell {
7671 file_dir_handle : ShellFileHandle ,
7772 out_file_list : * mut * mut ShellFileInfo ,
7873 ) -> 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 ,
8375
8476 open_root : usize ,
8577 open_root_by_handle : usize ,
@@ -164,6 +156,7 @@ impl Shell {
164156 /// # Returns
165157 ///
166158 /// * `Some(env_value)` - Value of the environment variable
159+ /// * `Some(Vec<env_names>)` - Vector of environment variable names
167160 /// * `None` - Environment variable doesn't exist
168161 pub fn get_env < ' a > ( & ' a self , name : Option < & CStr16 > ) -> Option < EnvOutput < ' a > > {
169162 match name {
@@ -178,7 +171,7 @@ impl Shell {
178171 }
179172 None => {
180173 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 ( ) ) ;
182175
183176 let mut cur_start = cur_env_ptr;
184177 let mut cur_len = 0 ;
@@ -189,14 +182,13 @@ impl Shell {
189182 while null_count <= 1 {
190183 if ( * ( cur_env_ptr. add ( i) ) ) == Char16 :: from_u16_unchecked ( 0 ) {
191184 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+ ) ) ;
195188 }
196189 cur_len = 0 ;
197190 null_count += 1 ;
198- }
199- else {
191+ } else {
200192 if null_count > 0 {
201193 cur_start = cur_env_ptr. add ( i) ;
202194 }
@@ -274,22 +266,17 @@ impl Shell {
274266 /// * `file_attribs` - Attributes of the new file
275267 /// * `file_handle` - On return, points to the created file/directory's
276268 /// 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 > {
282270 // TODO: Find out how we could take a &str instead, or maybe AsRef<str>, though I think it needs `alloc`
283271 // the returned handle can possibly be NULL, so we need to wrap `ShellFileHandle` in an `Option`
284272 //let mut out_file_handle: MaybeUninit<Option<ShellFileHandle>> = MaybeUninit::zeroed();
285273 // let mut file_handle: ShellFileHandle;
286274 let file_handle = ptr:: null ( ) ;
287275
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() })
293280 }
294281
295282 /// TODO
0 commit comments