Skip to content

Commit 2fe4e79

Browse files
authored
Refactor util_libc (#765)
This PR refactors `util_libc`, `sanitizer`, and `lazy` modules. The modules are moved into the `utils` directory and "mounted" with `#[path = ".."]`. With this change all uses of `#[path = ".."]` point towards the `utils` directory.
1 parent af7fec1 commit 2fe4e79

18 files changed

+285
-207
lines changed

Cargo.lock

Lines changed: 150 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backends.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ cfg_if! {
1313
pub use custom::*;
1414
} else if #[cfg(getrandom_backend = "linux_getrandom")] {
1515
mod getrandom;
16-
mod sanitizer;
1716
pub use getrandom::*;
1817
} else if #[cfg(getrandom_backend = "linux_raw")] {
1918
mod linux_raw;
20-
mod sanitizer;
2119
pub use linux_raw::*;
2220
} else if #[cfg(getrandom_backend = "rdrand")] {
2321
mod rdrand;
@@ -49,7 +47,6 @@ cfg_if! {
4947
pub use unsupported::*;
5048
} else if #[cfg(all(target_os = "linux", target_env = ""))] {
5149
mod linux_raw;
52-
mod sanitizer;
5350
pub use linux_raw::*;
5451
} else if #[cfg(target_os = "espidf")] {
5552
mod esp_idf;
@@ -117,7 +114,6 @@ cfg_if! {
117114
))] {
118115
mod use_file;
119116
mod linux_android_with_fallback;
120-
mod sanitizer;
121117
pub use linux_android_with_fallback::*;
122118
} else if #[cfg(any(
123119
target_os = "android",
@@ -132,8 +128,6 @@ cfg_if! {
132128
all(target_os = "horizon", target_arch = "arm"),
133129
))] {
134130
mod getrandom;
135-
#[cfg(any(target_os = "android", target_os = "linux"))]
136-
mod sanitizer;
137131
pub use getrandom::*;
138132
} else if #[cfg(target_os = "solaris")] {
139133
mod solaris;

src/backends/getentropy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ use core::{ffi::c_void, mem::MaybeUninit};
1212

1313
pub use crate::util::{inner_u32, inner_u64};
1414

15-
#[path = "../util_libc.rs"]
16-
mod util_libc;
15+
#[path = "../utils/get_errno.rs"]
16+
mod utils;
1717

1818
#[inline]
1919
pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
2020
for chunk in dest.chunks_mut(256) {
2121
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr().cast::<c_void>(), chunk.len()) };
2222
if ret != 0 {
23-
return Err(util_libc::last_os_error());
23+
let errno = utils::get_errno();
24+
return Err(Error::from_errno(errno));
2425
}
2526
}
2627
Ok(())

0 commit comments

Comments
 (0)