From 67be39af37abc8e445710b2d391b0328efe4f4f8 Mon Sep 17 00:00:00 2001 From: Eyob Date: Sun, 8 Sep 2024 23:21:24 +0300 Subject: [PATCH] Fix unused imports and gated feature for windows --- src/lib.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5e20eed..fbc7a08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,10 +8,21 @@ use core::{ any, fmt::{self, Debug}, }; -use errno::errno; -use libc::{madvise, mlock, munlock, sysconf, MADV_DODUMP, MADV_DONTDUMP, _SC_PAGESIZE}; +use std::mem::size_of_val; use std::ops::{Deref, DerefMut}; -use std::{ffi::c_void, mem::size_of_val}; + +#[cfg(unix)] +use errno::errno; + +#[cfg(unix)] +use std::ffi::c_void; + +#[cfg(unix)] +use libc::{mlock, munlock, sysconf, _SC_PAGESIZE}; + +#[cfg(target_os = "linux")] +use libc::{madvise, MADV_DODUMP, MADV_DONTDUMP}; + pub use zeroize; use zeroize::{Zeroize, ZeroizeOnDrop}; @@ -55,6 +66,7 @@ impl Drop for SecretBox { #[cfg(windows)] unsafe { + #[cfg(feature = "Win32")] if windows_sys::Win32::System::Memory::VirtualUnlock(secret_ptr.cast(), len) == 0 { panic!( "VirtualUnlock failed: {:?}", @@ -103,6 +115,7 @@ impl SecretBox { #[cfg(windows)] unsafe { + #[cfg(feature = "Win32")] if windows_sys::Win32::System::Memory::VirtualLock(secret_ptr.cast(), len) == 0 { panic!( "VirtualLock failed: {:?}",