mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 16:41:21 +00:00
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:
committed by
Lachlan Sneff
parent
663de770bf
commit
ce03e4464c
14
lib/emscripten/src/env/windows/mod.rs
vendored
14
lib/emscripten/src/env/windows/mod.rs
vendored
@ -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)]
|
||||
|
@ -2,6 +2,7 @@ use super::env;
|
||||
use super::env::get_emscripten_data;
|
||||
use libc::stat;
|
||||
use std::ffi::CStr;
|
||||
use std::ffi::CString;
|
||||
use std::mem::size_of;
|
||||
use std::os::raw::c_char;
|
||||
use std::os::raw::c_int;
|
||||
@ -158,11 +159,12 @@ pub unsafe fn copy_stat_into_wasm(ctx: &mut Ctx, buf: u32, stat: &stat) {
|
||||
}
|
||||
|
||||
pub fn read_string_from_wasm(memory: &Memory, offset: u32) -> String {
|
||||
memory.view::<u8>()[(offset as usize)..]
|
||||
let v: Vec<u8> = memory.view()[(offset as usize)..]
|
||||
.iter()
|
||||
.take_while(|cell| cell.get() != 0)
|
||||
.map(|cell| cell.get() as char)
|
||||
.collect()
|
||||
.map(|cell| cell.get())
|
||||
.take_while(|&byte| byte != 0)
|
||||
.collect();
|
||||
String::from_utf8_lossy(&v).to_owned().to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user