mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 00:08:56 +00:00
WASI clock functions
This commit is contained in:
parent
c3d93cd9f2
commit
14e9c7d1f2
@ -76,3 +76,35 @@ pub extern "wasi_unstable" fn sched_yield() errno_t;
|
||||
pub extern "wasi_unstable" fn sock_recv(sock: fd_t, ri_data: *const iovec_t, ri_data_len: usize, ri_flags: riflags_t, ro_datalen: *usize, ro_flags: *roflags_t) errno_t;
|
||||
pub extern "wasi_unstable" fn sock_send(sock: fd_t, si_data: *const ciovec_t, si_data_len: usize, si_flags: siflags_t, so_datalen: *usize) errno_t;
|
||||
pub extern "wasi_unstable" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t;
|
||||
|
||||
/// Get the errno from a syscall return value, or 0 for no error.
|
||||
pub fn getErrno(r: usize) usize {
|
||||
const signed_r = @bitCast(isize, r);
|
||||
return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0;
|
||||
}
|
||||
|
||||
pub fn clock_getres(clock_id: i32, res: *timespec) errno_t {
|
||||
var ts: timestamp_t = undefined;
|
||||
const err = clock_res_get(@bitCast(u32, clock_id), &ts);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
res.* = .{
|
||||
.tv_sec = @intCast(i64, ts / 1000000000),
|
||||
.tv_nsec = @intCast(isize, ts % 1000000000),
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn clock_gettime(clock_id: i32, tp: *timespec) errno_t {
|
||||
var ts: timestamp_t = undefined;
|
||||
const err = clock_time_get(@bitCast(u32, clock_id), 1, &ts);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
tp.* = .{
|
||||
.tv_sec = @intCast(i64, ts / 1000000000),
|
||||
.tv_nsec = @intCast(isize, ts % 1000000000),
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user