@@ -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 :: { HANDLE as RAW_HANDLE , INVALID_HANDLE_VALUE } ;
@@ -235,13 +236,12 @@ fn attributes_from_dir(
235236 windows_sys:: Win32 :: Storage :: FileSystem :: BY_HANDLE_FILE_INFORMATION ,
236237 u32 ,
237238) > {
238- use std:: os:: windows:: ffi:: OsStrExt ;
239239 use windows_sys:: Win32 :: Storage :: FileSystem :: {
240240 BY_HANDLE_FILE_INFORMATION , FILE_ATTRIBUTE_REPARSE_POINT , FindClose , FindFirstFileW ,
241241 WIN32_FIND_DATAW ,
242242 } ;
243243
244- let wide: Vec < u16 > = path. encode_wide ( ) . chain ( std :: iter :: once ( 0 ) ) . collect ( ) ;
244+ let wide: Vec < u16 > = path. to_wide_with_nul ( ) ;
245245 let mut find_data: WIN32_FIND_DATAW = unsafe { std:: mem:: zeroed ( ) } ;
246246
247247 let handle = unsafe { FindFirstFileW ( wide. as_ptr ( ) , & mut find_data) } ;
@@ -269,7 +269,6 @@ fn attributes_from_dir(
269269
270270/// Ported from win32_xstat_slow_impl
271271fn win32_xstat_slow_impl ( path : & OsStr , traverse : bool ) -> std:: io:: Result < StatStruct > {
272- use std:: os:: windows:: ffi:: OsStrExt ;
273272 use windows_sys:: Win32 :: {
274273 Foundation :: {
275274 CloseHandle , ERROR_ACCESS_DENIED , ERROR_CANT_ACCESS_FILE , ERROR_INVALID_FUNCTION ,
@@ -287,7 +286,7 @@ fn win32_xstat_slow_impl(path: &OsStr, traverse: bool) -> std::io::Result<StatSt
287286 } ,
288287 } ;
289288
290- let wide: Vec < u16 > = path. encode_wide ( ) . chain ( std :: iter :: once ( 0 ) ) . collect ( ) ;
289+ let wide: Vec < u16 > = path. to_wide_with_nul ( ) ;
291290
292291 let access = FILE_READ_ATTRIBUTES ;
293292 let mut flags = FILE_FLAG_BACKUP_SEMANTICS ;
0 commit comments