fill unsetenv for windows (#150)

* fill unsetenv

* update usage of read_string_from_wasm

* convert helper to return String

* correct usage of helper fn, cargo fmt, and check in lock file change
This commit is contained in:
Mackenzie Clark
2019-02-07 10:51:19 -08:00
committed by Lachlan Sneff
parent 663de770bf
commit ce03e4464c
3 changed files with 42 additions and 10 deletions

View File

@ -70,14 +70,16 @@ pub fn _putenv(name: c_int, ctx: &mut Ctx) -> c_int {
}
/// emscripten: _unsetenv // (name: *const char);
pub fn _unsetenv(name: c_int, ctx: &mut Ctx) -> c_int {
pub fn _unsetenv(name: u32, ctx: &mut Ctx) -> c_int {
debug!("emscripten::_unsetenv");
let name_addr = emscripten_memory_pointer!(ctx.memory(0), name);
debug!("=> name({:?})", unsafe { CStr::from_ptr(name_addr) });
unsafe { unsetenv(name_addr) }
let name = read_string_from_wasm(ctx.memory(0), name);
// no unsetenv on windows, so use putenv with an empty value
let unsetenv_string = format!("{}=", name);
let unsetenv_cstring = CString::new(unsetenv_string).unwrap();
let unsetenv_raw_ptr = unsetenv_cstring.as_ptr();
debug!("=> name({:?})", name);
unsafe { putenv(unsetenv_raw_ptr) }
}
#[allow(clippy::cast_ptr_alignment)]