Improved rename function

This commit is contained in:
Syrus
2019-05-05 12:09:27 -07:00
parent 10a965cc1e
commit 2ba680ad2f
2 changed files with 20 additions and 4 deletions

View File

@ -36,6 +36,7 @@ use libc::{
// writev, // writev,
stat, stat,
write, write,
rename,
// sockaddr_in, // sockaddr_in,
}; };
use wasmer_runtime_core::vm::Ctx; use wasmer_runtime_core::vm::Ctx;
@ -118,9 +119,23 @@ pub fn ___syscall20(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
unsafe { getpid() } unsafe { getpid() }
} }
pub fn ___syscall38(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 { // rename
debug!("emscripten::___syscall38"); pub fn ___syscall38(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 {
-1 debug!("emscripten::___syscall38 (rename)");
let old_path_addr: u32 = varargs.get(ctx);
let new_path_addr: u32 = varargs.get(ctx);
let old_path = emscripten_memory_pointer!(ctx.memory(0), old_path_addr) as *const i8;
let new_path = emscripten_memory_pointer!(ctx.memory(0), new_path_addr) as *const i8;
let result = unsafe { rename(old_path, new_path) };
unsafe {
debug!(
"=> old_path: {}, new_path: {}, result: {}",
std::ffi::CStr::from_ptr(old_path).to_str().unwrap(),
std::ffi::CStr::from_ptr(new_path).to_str().unwrap(),
result
);
}
result
} }
// rmdir // rmdir

View File

@ -251,8 +251,9 @@ pub fn ___syscall33(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8; let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8;
let result = unsafe { access(path, amode) }; let result = unsafe { access(path, amode) };
debug!( debug!(
"=> path: {}, result: {}", "=> path: {}, amode: {}, result: {}",
unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() }, unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() },
amode,
result result
); );
result result