Skip to content

Commit

Permalink
Switch from winapi to windows-sys
Browse files Browse the repository at this point in the history
The ecosystem is switching from winapi to the Microsoft-maintained windows-sys. Follow suit so
depentents don't have to compile both.

This raises the MSRV to 1.48.
  • Loading branch information
LingMan committed Dec 16, 2022
1 parent 131cf50 commit 11dfeff
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
rust: [stable, nightly, 1.36.0]
rust: [stable, nightly, 1.48]
exclude:
# TODO(#52): Investigate why this is broken
- os: macos-latest
rust: 1.36.0
rust: 1.48
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

- Add formatting with `#![no_std]`
[#44](https://github.com/lambda-fairy/rust-errno/pull/44)

- Update minimum Rust version to 1.36
[#48](https://github.com/lambda-fairy/rust-errno/pull/48)

- Switch from `winapi` to `windows-sys` [#55](https://github.com/lambda-fairy/rust-errno/pull/55)

- Update minimum Rust version to 1.48
[#48](https://github.com/lambda-fairy/rust-errno/pull/48) [#55](https://github.com/lambda-fairy/rust-errno/pull/55)

# [0.2.8] - 2021-10-27

Expand Down
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ categories = ["no-std", "os"]
[target.'cfg(unix)'.dependencies]
libc = "0.2"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["errhandlingapi", "minwindef", "ntdef", "winbase"] }
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.42"
features = [
"Win32_Foundation",
"Win32_System_Diagnostics_Debug",
]

[target.'cfg(target_os="dragonfly")'.dependencies]
errno-dragonfly = "0.1.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# errno [![CI](https://github.com/lambda-fairy/rust-errno/actions/workflows/main.yml/badge.svg)](https://github.com/lambda-fairy/rust-errno/actions/workflows/main.yml) [![Cargo](https://img.shields.io/crates/v/errno.svg)](https://crates.io/crates/errno)

Cross-platform interface to the [`errno`][errno] variable. Works on Rust 1.36 or newer.
Cross-platform interface to the [`errno`][errno] variable. Works on Rust 1.48 or newer.

Documentation is available at <https://docs.rs/errno>.

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern crate libc;
#[cfg(target_os = "hermit")]
extern crate libc;
#[cfg(windows)]
extern crate winapi;
extern crate windows_sys;

#[cfg_attr(unix, path = "unix.rs")]
#[cfg_attr(windows, path = "windows.rs")]
Expand Down
21 changes: 11 additions & 10 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
use core::char::{self, REPLACEMENT_CHARACTER};
use core::ptr;
use core::str;
use winapi::shared::minwindef::DWORD;
use winapi::shared::ntdef::WCHAR;
use winapi::um::winbase::{FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS};
use windows_sys::Win32::Foundation::{GetLastError, SetLastError, WIN32_ERROR};
use windows_sys::Win32::System::Diagnostics::Debug::{
FormatMessageW, FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS,
};

use Errno;

Expand All @@ -42,18 +43,18 @@ where
{
// This value is calculated from the macro
// MAKELANGID(LANG_SYSTEM_DEFAULT, SUBLANG_SYS_DEFAULT)
let lang_id = 0x0800 as DWORD;
let lang_id = 0x0800_u32;

let mut buf = [0 as WCHAR; 2048];
let mut buf = [0u16; 2048];

unsafe {
let res = ::winapi::um::winbase::FormatMessageW(
let res = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
ptr::null_mut(),
err.0 as DWORD,
err.0 as u32,
lang_id,
buf.as_mut_ptr(),
buf.len() as DWORD,
buf.len() as u32,
ptr::null_mut(),
);
if res == 0 {
Expand All @@ -73,9 +74,9 @@ where
pub const STRERROR_NAME: &'static str = "FormatMessageW";

pub fn errno() -> Errno {
unsafe { Errno(::winapi::um::errhandlingapi::GetLastError() as i32) }
unsafe { Errno(GetLastError() as i32) }
}

pub fn set_errno(Errno(errno): Errno) {
unsafe { ::winapi::um::errhandlingapi::SetLastError(errno as DWORD) }
unsafe { SetLastError(errno as WIN32_ERROR) }
}

0 comments on commit 11dfeff

Please sign in to comment.