Skip to content

Commit f2a927f

Browse files
committed
Switch from winapi to windows-sys
1 parent 6633c0e commit f2a927f

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ libc = { version = "0.2", default-features = false }
2020
[target.'cfg(target_os = "hermit")'.dependencies]
2121
hermit-abi = "0.1.6"
2222

23-
[target.'cfg(windows)'.dependencies.winapi]
24-
version = "0.3"
25-
features = ["consoleapi", "processenv", "minwinbase", "minwindef", "winbase"]
23+
[target.'cfg(windows)'.dependencies.windows-sys]
24+
version = "0.36"
25+
features = ["Win32_System_Console", "Win32_Foundation", "Win32_Storage_FileSystem"]
2626

src/lib.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
#[cfg(unix)]
2121
extern crate libc;
2222
#[cfg(windows)]
23-
extern crate winapi;
23+
extern crate windows_sys;
2424

2525
#[cfg(windows)]
26-
use winapi::shared::minwindef::DWORD;
27-
#[cfg(windows)]
28-
use winapi::shared::ntdef::WCHAR;
26+
use windows_sys::Win32::System::Console::STD_HANDLE;
2927

3028
/// possible stream sources
3129
#[derive(Clone, Copy, Debug)]
@@ -64,7 +62,7 @@ pub fn is(stream: Stream) -> bool {
6462
/// returns true if this is a tty
6563
#[cfg(windows)]
6664
pub fn is(stream: Stream) -> bool {
67-
use winapi::um::winbase::{
65+
use windows_sys::Win32::System::Console::{
6866
STD_ERROR_HANDLE as STD_ERROR, STD_INPUT_HANDLE as STD_INPUT,
6967
STD_OUTPUT_HANDLE as STD_OUTPUT,
7068
};
@@ -100,8 +98,8 @@ pub fn isnt(stream: Stream) -> bool {
10098

10199
/// Returns true if any of the given fds are on a console.
102100
#[cfg(windows)]
103-
unsafe fn console_on_any(fds: &[DWORD]) -> bool {
104-
use winapi::um::{consoleapi::GetConsoleMode, processenv::GetStdHandle};
101+
unsafe fn console_on_any(fds: &[STD_HANDLE]) -> bool {
102+
use windows_sys::Win32::System::Console::{GetConsoleMode, GetStdHandle};
105103

106104
for &fd in fds {
107105
let mut out = 0;
@@ -115,20 +113,18 @@ unsafe fn console_on_any(fds: &[DWORD]) -> bool {
115113

116114
/// Returns true if there is an MSYS tty on the given handle.
117115
#[cfg(windows)]
118-
unsafe fn msys_tty_on(fd: DWORD) -> bool {
116+
unsafe fn msys_tty_on(fd: STD_HANDLE) -> bool {
119117
use std::{mem, slice};
120118

121-
use winapi::{
122-
ctypes::c_void,
123-
shared::minwindef::MAX_PATH,
124-
um::{
125-
fileapi::FILE_NAME_INFO, minwinbase::FileNameInfo, processenv::GetStdHandle,
126-
winbase::GetFileInformationByHandleEx,
127-
},
119+
use std::ffi::c_void;
120+
use windows_sys::Win32::{
121+
Foundation::MAX_PATH,
122+
Storage::FileSystem::{FileNameInfo, GetFileInformationByHandleEx, FILE_NAME_INFO},
123+
System::Console::GetStdHandle,
128124
};
129125

130126
let size = mem::size_of::<FILE_NAME_INFO>();
131-
let mut name_info_bytes = vec![0u8; size + MAX_PATH * mem::size_of::<WCHAR>()];
127+
let mut name_info_bytes = vec![0u8; size + (MAX_PATH as usize) * mem::size_of::<u16>()];
132128
let res = GetFileInformationByHandleEx(
133129
GetStdHandle(fd),
134130
FileNameInfo,

0 commit comments

Comments
 (0)