Skip to content

Commit 20b51b8

Browse files
committed
Reimplement std_detect_env_override using libc instead of std
1 parent 1b267f7 commit 20b51b8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/std_detect/src/detect/cache.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,16 @@ cfg_if::cfg_if! {
125125
if #[cfg(feature = "std_detect_env_override")] {
126126
#[inline]
127127
fn initialize(mut value: Initializer) -> Initializer {
128-
if let Ok(disable) = crate::env::var("RUST_STD_DETECT_UNSTABLE") {
129-
for v in disable.split(" ") {
130-
let _ = super::Feature::from_str(v).map(|v| value.unset(v as u32));
128+
let env = unsafe {
129+
libc::getenv(b"RUST_STD_DETECT_UNSTABLE\0".as_ptr() as *const libc::c_char)
130+
};
131+
if !env.is_null() {
132+
let len = unsafe { libc::strlen(env) };
133+
let env = unsafe { core::slice::from_raw_parts(env as *const u8, len) };
134+
if let Ok(disable) = core::str::from_utf8(env) {
135+
for v in disable.split(" ") {
136+
let _ = super::Feature::from_str(v).map(|v| value.unset(v as u32));
137+
}
131138
}
132139
}
133140
do_initialize(value);

0 commit comments

Comments
 (0)