1- #![ allow( unsafe_op_in_unsafe_fn) ]
21use crate :: marker:: PhantomData ;
32use crate :: mem:: size_of;
43use crate :: os:: windows:: io:: { AsHandle , AsRawHandle , BorrowedHandle } ;
@@ -81,19 +80,17 @@ impl<'a> IoSliceMut<'a> {
8180}
8281
8382pub fn is_terminal ( h : & impl AsHandle ) -> bool {
84- unsafe { handle_is_console ( h. as_handle ( ) ) }
83+ handle_is_console ( h. as_handle ( ) )
8584}
8685
87- unsafe fn handle_is_console ( handle : BorrowedHandle < ' _ > ) -> bool {
88- let handle = handle. as_raw_handle ( ) ;
89-
86+ fn handle_is_console ( handle : BorrowedHandle < ' _ > ) -> bool {
9087 // A null handle means the process has no console.
91- if handle. is_null ( ) {
88+ if handle. as_raw_handle ( ) . is_null ( ) {
9289 return false ;
9390 }
9491
9592 let mut out = 0 ;
96- if c:: GetConsoleMode ( handle, & mut out) != 0 {
93+ if unsafe { c:: GetConsoleMode ( handle. as_raw_handle ( ) , & mut out) != 0 } {
9794 // False positives aren't possible. If we got a console then we definitely have a console.
9895 return true ;
9996 }
@@ -102,9 +99,9 @@ unsafe fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
10299 msys_tty_on ( handle)
103100}
104101
105- unsafe fn msys_tty_on ( handle : c :: HANDLE ) -> bool {
102+ fn msys_tty_on ( handle : BorrowedHandle < ' _ > ) -> bool {
106103 // Early return if the handle is not a pipe.
107- if c:: GetFileType ( handle) != c:: FILE_TYPE_PIPE {
104+ if unsafe { c:: GetFileType ( handle. as_raw_handle ( ) ) != c:: FILE_TYPE_PIPE } {
108105 return false ;
109106 }
110107
@@ -120,12 +117,14 @@ unsafe fn msys_tty_on(handle: c::HANDLE) -> bool {
120117 }
121118 let mut name_info = FILE_NAME_INFO { FileNameLength : 0 , FileName : [ 0 ; c:: MAX_PATH as usize ] } ;
122119 // Safety: buffer length is fixed.
123- let res = c:: GetFileInformationByHandleEx (
124- handle,
125- c:: FileNameInfo ,
126- core:: ptr:: addr_of_mut!( name_info) as * mut c_void ,
127- size_of :: < FILE_NAME_INFO > ( ) as u32 ,
128- ) ;
120+ let res = unsafe {
121+ c:: GetFileInformationByHandleEx (
122+ handle. as_raw_handle ( ) ,
123+ c:: FileNameInfo ,
124+ core:: ptr:: addr_of_mut!( name_info) as * mut c_void ,
125+ size_of :: < FILE_NAME_INFO > ( ) as u32 ,
126+ )
127+ } ;
129128 if res == 0 {
130129 return false ;
131130 }
0 commit comments