Skip to content

Commit

Permalink
Switch from winapi to windows-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
arlosi committed May 25, 2022
1 parent 6633c0e commit f2a927f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ libc = { version = "0.2", default-features = false }
[target.'cfg(target_os = "hermit")'.dependencies]
hermit-abi = "0.1.6"

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

28 changes: 12 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
#[cfg(unix)]
extern crate libc;
#[cfg(windows)]
extern crate winapi;
extern crate windows_sys;

#[cfg(windows)]
use winapi::shared::minwindef::DWORD;
#[cfg(windows)]
use winapi::shared::ntdef::WCHAR;
use windows_sys::Win32::System::Console::STD_HANDLE;

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

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

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

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

use winapi::{
ctypes::c_void,
shared::minwindef::MAX_PATH,
um::{
fileapi::FILE_NAME_INFO, minwinbase::FileNameInfo, processenv::GetStdHandle,
winbase::GetFileInformationByHandleEx,
},
use std::ffi::c_void;
use windows_sys::Win32::{
Foundation::MAX_PATH,
Storage::FileSystem::{FileNameInfo, GetFileInformationByHandleEx, FILE_NAME_INFO},
System::Console::GetStdHandle,
};

let size = mem::size_of::<FILE_NAME_INFO>();
let mut name_info_bytes = vec![0u8; size + MAX_PATH * mem::size_of::<WCHAR>()];
let mut name_info_bytes = vec![0u8; size + (MAX_PATH as usize) * mem::size_of::<u16>()];
let res = GetFileInformationByHandleEx(
GetStdHandle(fd),
FileNameInfo,
Expand Down

0 comments on commit f2a927f

Please sign in to comment.