Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from winapi to windows-sys #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.42"
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