2020-03-07 10:35:00 -06:00
|
|
|
//ignore-windows: TODO env var emulation stubbed out on Windows
|
|
|
|
|
|
|
|
#[cfg(target_os="linux")]
|
|
|
|
fn get_environ() -> *const *const u8 {
|
|
|
|
extern "C" {
|
2020-03-07 14:33:27 -06:00
|
|
|
static mut environ: *const *const u8;
|
2020-03-07 10:35:00 -06:00
|
|
|
}
|
2020-03-07 14:33:27 -06:00
|
|
|
unsafe { environ }
|
2020-03-07 10:35:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os="macos")]
|
|
|
|
fn get_environ() -> *const *const u8 {
|
|
|
|
extern "C" {
|
|
|
|
fn _NSGetEnviron() -> *mut *const *const u8;
|
|
|
|
}
|
|
|
|
unsafe { *_NSGetEnviron() }
|
2020-03-07 08:26:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-03-07 10:35:00 -06:00
|
|
|
let pointer = get_environ();
|
2020-03-07 08:26:04 -06:00
|
|
|
let _x = unsafe { *pointer };
|
|
|
|
std::env::set_var("FOO", "BAR");
|
|
|
|
let _y = unsafe { *pointer }; //~ ERROR dangling pointer was dereferenced
|
|
|
|
}
|