@@ -18,7 +18,8 @@ use crate::sys::{c, cvt, Align8};
1818use  crate :: sys_common:: { AsInner ,  FromInner ,  IntoInner } ; 
1919use  crate :: thread; 
2020
21- use  super :: { api,  to_u16s,  IoResult } ; 
21+ use  super :: api:: { self ,  WinError } ; 
22+ use  super :: { to_u16s,  IoResult } ; 
2223use  crate :: sys:: path:: maybe_verbatim; 
2324
2425pub  struct  File  { 
@@ -130,10 +131,11 @@ impl Iterator for ReadDir {
130131            let  mut  wfd = mem:: zeroed ( ) ; 
131132            loop  { 
132133                if  c:: FindNextFileW ( self . handle . 0 ,  & mut  wfd)  == 0  { 
133-                     if  api:: get_last_error ( ) . code  == c:: ERROR_NO_MORE_FILES  { 
134-                         return  None ; 
135-                     }  else  { 
136-                         return  Some ( Err ( Error :: last_os_error ( ) ) ) ; 
134+                     match  api:: get_last_error ( )  { 
135+                         WinError :: NO_MORE_FILES  => return  None , 
136+                         WinError  {  code }  => { 
137+                             return  Some ( Err ( Error :: from_raw_os_error ( code as  i32 ) ) ) ; 
138+                         } 
137139                    } 
138140                } 
139141                if  let  Some ( e)  = DirEntry :: new ( & self . root ,  & wfd)  { 
@@ -244,8 +246,6 @@ impl OpenOptions {
244246    } 
245247
246248    fn  get_access_mode ( & self )  -> io:: Result < c:: DWORD >  { 
247-         const  ERROR_INVALID_PARAMETER :  i32  = 87 ; 
248- 
249249        match  ( self . read ,  self . write ,  self . append ,  self . access_mode )  { 
250250            ( ..,  Some ( mode) )  => Ok ( mode) , 
251251            ( true ,  false ,  false ,  None )  => Ok ( c:: GENERIC_READ ) , 
@@ -255,23 +255,23 @@ impl OpenOptions {
255255            ( true ,  _,  true ,  None )  => { 
256256                Ok ( c:: GENERIC_READ  | ( c:: FILE_GENERIC_WRITE  &  !c:: FILE_WRITE_DATA ) ) 
257257            } 
258-             ( false ,  false ,  false ,  None )  => Err ( Error :: from_raw_os_error ( ERROR_INVALID_PARAMETER ) ) , 
258+             ( false ,  false ,  false ,  None )  => { 
259+                 Err ( Error :: from_raw_os_error ( c:: ERROR_INVALID_PARAMETER  as  i32 ) ) 
260+             } 
259261        } 
260262    } 
261263
262264    fn  get_creation_mode ( & self )  -> io:: Result < c:: DWORD >  { 
263-         const  ERROR_INVALID_PARAMETER :  i32  = 87 ; 
264- 
265265        match  ( self . write ,  self . append )  { 
266266            ( true ,  false )  => { } 
267267            ( false ,  false )  => { 
268268                if  self . truncate  || self . create  || self . create_new  { 
269-                     return  Err ( Error :: from_raw_os_error ( ERROR_INVALID_PARAMETER ) ) ; 
269+                     return  Err ( Error :: from_raw_os_error ( c :: ERROR_INVALID_PARAMETER   as   i32 ) ) ; 
270270                } 
271271            } 
272272            ( _,  true )  => { 
273273                if  self . truncate  && !self . create_new  { 
274-                     return  Err ( Error :: from_raw_os_error ( ERROR_INVALID_PARAMETER ) ) ; 
274+                     return  Err ( Error :: from_raw_os_error ( c :: ERROR_INVALID_PARAMETER   as   i32 ) ) ; 
275275                } 
276276            } 
277277        } 
@@ -315,7 +315,7 @@ impl File {
315315            // Manual truncation. See #115745. 
316316            if  opts. truncate 
317317                && creation == c:: OPEN_ALWAYS 
318-                 && unsafe   {  c :: GetLastError ( )  }   == c :: ERROR_ALREADY_EXISTS 
318+                 && api :: get_last_error ( )  == WinError :: ALREADY_EXISTS 
319319            { 
320320                unsafe  { 
321321                    // This originally used `FileAllocationInfo` instead of 
@@ -845,7 +845,7 @@ fn open_link_no_reparse(parent: &File, name: &[u16], access: u32) -> io::Result<
845845            // We make a special exception for `STATUS_DELETE_PENDING` because 
846846            // otherwise this will be mapped to `ERROR_ACCESS_DENIED` which is 
847847            // very unhelpful. 
848-             Err ( io:: Error :: from_raw_os_error ( c:: ERROR_DELETE_PENDING  as  _ ) ) 
848+             Err ( io:: Error :: from_raw_os_error ( c:: ERROR_DELETE_PENDING  as  i32 ) ) 
849849        }  else  if  status == c:: STATUS_INVALID_PARAMETER 
850850            && ATTRIBUTES . load ( Ordering :: Relaxed )  == c:: OBJ_DONT_REPARSE 
851851        { 
@@ -1097,7 +1097,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
10971097            // 
10981098            // See issue #120040: https://github.com/rust-lang/rust/issues/120040. 
10991099            let  last_error = api:: get_last_error ( ) ; 
1100-             if  last_error. code  == c :: ERROR_FILE_NOT_FOUND  { 
1100+             if  last_error == WinError :: FILE_NOT_FOUND  { 
11011101                return  Ok ( ReadDir  { 
11021102                    handle :  FindNextFileHandle ( find_handle) , 
11031103                    root :  Arc :: new ( root) , 
0 commit comments