use chillffi::ffi::allocatedMemory::{AllocatedMemory};
use chillffi::ffi::value::{Type, Value};
use chillffi::ffi::errors::FFIError;
use chillffi::ffi;
fn main() -> ()
{
let (secs, nanos): (i64, i64) = ffi!(|scope| {
let libc: Library = Library::load("libc.so.6")?;
let mem: AllocatedMemory = scope.alloc(16)?;
libc.call("clock_gettime", vec![Value::I32(0 ), mem.asPointer()], Type::I32)?;
let Value::RawString(bytes) = mem.read()? else {
return Err(FFIError::Other("expected bytes".into()))
};
drop(mem);
let secs: i64 = i64::from_ne_bytes(bytes[0..8].try_into().unwrap());
let nanos: i64 = i64::from_ne_bytes(bytes[8..16].try_into().unwrap());
Ok((secs, nanos))
}).expect("clock_gettime failed");
println!("clock_gettime(CLOCK_REALTIME) = {}.{:09}", secs, nanos);
}