@@ -7,6 +7,7 @@ use crate::{
77 convert:: { ToPyObject , ToPyResult } ,
88 stdlib:: os:: errno_err,
99} ;
10+ use rustpython_common:: windows:: ToWideString ;
1011use std:: ffi:: OsStr ;
1112use windows:: Win32 :: Foundation :: HANDLE ;
1213use windows_sys:: Win32 :: Foundation :: { BOOL , HANDLE as RAW_HANDLE , INVALID_HANDLE_VALUE } ;
@@ -234,13 +235,12 @@ fn attributes_from_dir(
234235 windows_sys:: Win32 :: Storage :: FileSystem :: BY_HANDLE_FILE_INFORMATION ,
235236 u32 ,
236237) > {
237- use std:: os:: windows:: ffi:: OsStrExt ;
238238 use windows_sys:: Win32 :: Storage :: FileSystem :: {
239239 BY_HANDLE_FILE_INFORMATION , FILE_ATTRIBUTE_REPARSE_POINT , FindClose , FindFirstFileW ,
240240 WIN32_FIND_DATAW ,
241241 } ;
242242
243- let wide: Vec < u16 > = path. encode_wide ( ) . chain ( std :: iter :: once ( 0 ) ) . collect ( ) ;
243+ let wide: Vec < u16 > = path. to_wide_with_nul ( ) ;
244244 let mut find_data: WIN32_FIND_DATAW = unsafe { std:: mem:: zeroed ( ) } ;
245245
246246 let handle = unsafe { FindFirstFileW ( wide. as_ptr ( ) , & mut find_data) } ;
@@ -268,7 +268,6 @@ fn attributes_from_dir(
268268
269269/// Ported from win32_xstat_slow_impl
270270fn win32_xstat_slow_impl ( path : & OsStr , traverse : bool ) -> std:: io:: Result < StatStruct > {
271- use std:: os:: windows:: ffi:: OsStrExt ;
272271 use windows_sys:: Win32 :: {
273272 Foundation :: {
274273 CloseHandle , ERROR_ACCESS_DENIED , ERROR_CANT_ACCESS_FILE , ERROR_INVALID_FUNCTION ,
@@ -286,7 +285,7 @@ fn win32_xstat_slow_impl(path: &OsStr, traverse: bool) -> std::io::Result<StatSt
286285 } ,
287286 } ;
288287
289- let wide: Vec < u16 > = path. encode_wide ( ) . chain ( std :: iter :: once ( 0 ) ) . collect ( ) ;
288+ let wide: Vec < u16 > = path. to_wide_with_nul ( ) ;
290289
291290 let access = FILE_READ_ATTRIBUTES ;
292291 let mut flags = FILE_FLAG_BACKUP_SEMANTICS ;
0 commit comments