Skip to content

Commit

Permalink
Replace errno dependency with calling Error::last_os_error
Browse files Browse the repository at this point in the history
The documentation for the errno crate specify that last_os_error fetch
the underlying errno in the exact same way, so this should be
equivalent, but with fewer dependencies
  • Loading branch information
faern committed May 29, 2024
1 parent 8548959 commit 5609300
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
38 changes: 2 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ travis-ci = { repository = "mullvad/pfctl-rs" }


[dependencies]
errno = "0.2"
error-chain = "0.12.4"
ioctl-sys = "0.6.0"
libc = "0.2.29"
Expand Down
6 changes: 4 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ macro_rules! ioctl_guard {
};
($func:expr, $already_active:expr) => {
if unsafe { $func } == $crate::macros::IOCTL_ERROR {
let ::errno::Errno(error_code) = ::errno::errno();
let io_error = ::std::io::Error::from_raw_os_error(error_code);
let io_error = ::std::io::Error::last_os_error();
let error_code = io_error
.raw_os_error()
.expect("Errors created with last_os_error should have errno");
let mut err = Err($crate::ErrorKind::IoctlError(io_error).into());
if error_code == $already_active {
err = err.chain_err(|| $crate::ErrorKind::StateAlreadyActive);
Expand Down

0 comments on commit 5609300

Please sign in to comment.