mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 22:08:45 +00:00
cargo fmt
This commit is contained in:
12
lib/emscripten/src/env/unix/mod.rs
vendored
12
lib/emscripten/src/env/unix/mod.rs
vendored
@@ -1,7 +1,5 @@
|
||||
/// NOTE: These syscalls only support wasm_32 for now because they take u32 offset
|
||||
use libc::{
|
||||
c_int, getgrnam as libc_getgrnam, getpwnam as libc_getpwnam, sysconf,
|
||||
};
|
||||
use libc::{c_int, getgrnam as libc_getgrnam, getpwnam as libc_getpwnam, sysconf};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::mem;
|
||||
use std::os::raw::c_char;
|
||||
@@ -29,7 +27,7 @@ pub fn _getenv(mut ctx: FunctionEnvMut<EmEnv>, name: i32) -> u32 {
|
||||
Some(s) => s,
|
||||
None => return 0,
|
||||
};
|
||||
let new_env_var = match CString::new(env_var) {
|
||||
let new_env_var = match CString::new(env_var) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return 0,
|
||||
};
|
||||
@@ -52,7 +50,7 @@ pub fn _setenv(ctx: FunctionEnvMut<EmEnv>, name: c_int, value: c_int, overwrite:
|
||||
debug!("=> value({:?})", value);
|
||||
|
||||
let previous_entry = em_env.set_env_var(name.as_ref(), value.as_ref());
|
||||
|
||||
|
||||
if let (0, Some(prev)) = (overwrite, previous_entry) {
|
||||
let _ = em_env.set_env_var(name.as_ref(), prev.as_ref());
|
||||
}
|
||||
@@ -84,7 +82,9 @@ pub fn _unsetenv(mut ctx: FunctionEnvMut<EmEnv>, name: c_int) -> c_int {
|
||||
let em_env = ctx.data();
|
||||
let memory = em_env.memory(0);
|
||||
let name_addr = emscripten_memory_pointer!(memory.view(&ctx), name) as *const c_char;
|
||||
unsafe { CStr::from_ptr(name_addr) }.to_string_lossy().to_string()
|
||||
unsafe { CStr::from_ptr(name_addr) }
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
};
|
||||
|
||||
debug!("=> name({:?})", name);
|
||||
|
||||
@@ -87,9 +87,8 @@ impl Default for EmscriptenState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
env_vars: std::env::vars_os()
|
||||
.filter_map(|(k, v)| {
|
||||
Some((k.to_str()?.to_string(), v.to_str()?.to_string()))
|
||||
}).collect(),
|
||||
.filter_map(|(k, v)| Some((k.to_str()?.to_string(), v.to_str()?.to_string())))
|
||||
.collect(),
|
||||
cli_args: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -155,10 +154,7 @@ impl EmEnv {
|
||||
*w = Some(EmscriptenData::new(data.clone(), mapped_dirs));
|
||||
}
|
||||
|
||||
pub fn get_env_var(
|
||||
&self,
|
||||
key: &str,
|
||||
) -> Option<String> {
|
||||
pub fn get_env_var(&self, key: &str) -> Option<String> {
|
||||
let w = self.state.lock().ok()?;
|
||||
let result = w.env_vars.get(key).cloned();
|
||||
result
|
||||
@@ -169,19 +165,12 @@ impl EmEnv {
|
||||
w.env_vars.len()
|
||||
}
|
||||
|
||||
pub fn set_env_var(
|
||||
&self,
|
||||
key: &str,
|
||||
value: &str,
|
||||
) -> Option<String> {
|
||||
pub fn set_env_var(&self, key: &str, value: &str) -> Option<String> {
|
||||
let mut w = self.state.lock().ok()?;
|
||||
w.env_vars.insert(key.to_string(), value.to_string())
|
||||
}
|
||||
|
||||
pub fn remove_env_var(
|
||||
&self,
|
||||
key: &str,
|
||||
) -> Option<String> {
|
||||
pub fn remove_env_var(&self, key: &str) -> Option<String> {
|
||||
let mut w = self.state.lock().ok()?;
|
||||
w.env_vars.remove(key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user