1
- #![ allow( unsafe_op_in_unsafe_fn) ]
2
1
use crate :: marker:: PhantomData ;
3
2
use crate :: mem:: size_of;
4
3
use crate :: os:: windows:: io:: { AsHandle , AsRawHandle , BorrowedHandle } ;
@@ -81,19 +80,17 @@ impl<'a> IoSliceMut<'a> {
81
80
}
82
81
83
82
pub fn is_terminal ( h : & impl AsHandle ) -> bool {
84
- unsafe { handle_is_console ( h. as_handle ( ) ) }
83
+ handle_is_console ( h. as_handle ( ) )
85
84
}
86
85
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 {
90
87
// A null handle means the process has no console.
91
- if handle. is_null ( ) {
88
+ if handle. as_raw_handle ( ) . is_null ( ) {
92
89
return false ;
93
90
}
94
91
95
92
let mut out = 0 ;
96
- if c:: GetConsoleMode ( handle, & mut out) != 0 {
93
+ if unsafe { c:: GetConsoleMode ( handle. as_raw_handle ( ) , & mut out) != 0 } {
97
94
// False positives aren't possible. If we got a console then we definitely have a console.
98
95
return true ;
99
96
}
@@ -102,9 +99,9 @@ unsafe fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
102
99
msys_tty_on ( handle)
103
100
}
104
101
105
- unsafe fn msys_tty_on ( handle : c :: HANDLE ) -> bool {
102
+ fn msys_tty_on ( handle : BorrowedHandle < ' _ > ) -> bool {
106
103
// 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 } {
108
105
return false ;
109
106
}
110
107
@@ -120,12 +117,14 @@ unsafe fn msys_tty_on(handle: c::HANDLE) -> bool {
120
117
}
121
118
let mut name_info = FILE_NAME_INFO { FileNameLength : 0 , FileName : [ 0 ; c:: MAX_PATH as usize ] } ;
122
119
// 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
+ } ;
129
128
if res == 0 {
130
129
return false ;
131
130
}
0 commit comments