mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 06:15:33 +00:00
Add _localtimeand _time functions
This commit is contained in:
parent
5911ac58c0
commit
b1ba24e99d
@ -6,6 +6,7 @@ use std::os::raw::c_char;
|
||||
use std::{slice, mem};
|
||||
|
||||
use crate::webassembly::Instance;
|
||||
use super::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
|
||||
|
||||
/// emscripten: _getenv
|
||||
pub extern "C" fn _getenv(name_ptr: c_int, instance: &mut Instance) -> c_int {
|
||||
@ -22,33 +23,6 @@ pub extern "C" fn _getenv(name_ptr: c_int, instance: &mut Instance) -> c_int {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn copy_cstr_into_wasm(instance: &mut Instance, cstr: *const c_char) -> u32 {
|
||||
let s = CStr::from_ptr(cstr).to_str().unwrap();
|
||||
let space_offset = (instance.emscripten_data.malloc)(s.len() as _, instance);
|
||||
let raw_memory = instance.memory_offset_addr(0, space_offset as _) as *mut u8;
|
||||
let mut slice = slice::from_raw_parts_mut(raw_memory, s.len());
|
||||
|
||||
for (byte, loc) in s.bytes().zip(slice.iter_mut()) {
|
||||
*loc = byte;
|
||||
}
|
||||
|
||||
space_offset
|
||||
}
|
||||
|
||||
unsafe fn copy_terminated_array_of_cstrs(instance: &mut Instance, cstrs: *mut *mut c_char) -> u32 {
|
||||
let total_num = {
|
||||
let mut ptr = cstrs;
|
||||
let mut counter = 0;
|
||||
while !(*ptr).is_null() {
|
||||
counter += 1;
|
||||
ptr = ptr.add(1);
|
||||
}
|
||||
counter
|
||||
};
|
||||
println!("total_num: {}", total_num);
|
||||
0
|
||||
}
|
||||
|
||||
pub extern "C" fn _getpwnam(name_ptr: c_int, instance: &mut Instance) -> c_int {
|
||||
#[repr(C)]
|
||||
struct GuestPasswd {
|
||||
@ -111,4 +85,4 @@ pub extern "C" fn _getgrnam(name_ptr: c_int, instance: &mut Instance) -> c_int {
|
||||
|
||||
group_struct_offset as c_int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user