| ... | ... | @@ -76,3 +76,35 @@ pub extern "wasi_unstable" fn sched_yield() errno_t; |
| 76 | 76 | 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; |
| 77 | 77 | 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; |
| 78 | 78 | pub extern "wasi_unstable" fn sock_shutdown(sock: fd_t, how: sdflags_t) errno_t; |
| 79 | |
| 80 | /// Get the errno from a syscall return value, or 0 for no error. |
| 81 | pub fn getErrno(r: usize) usize { |
| 82 | const signed_r = @bitCast(isize, r); |
| 83 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; |
| 84 | } |
| 85 | |
| 86 | pub fn clock_getres(clock_id: i32, res: *timespec) errno_t { |
| 87 | var ts: timestamp_t = undefined; |
| 88 | const err = clock_res_get(@bitCast(u32, clock_id), &ts); |
| 89 | if (err != 0) { |
| 90 | return err; |
| 91 | } |
| 92 | res.* = .{ |
| 93 | .tv_sec = @intCast(i64, ts / 1000000000), |
| 94 | .tv_nsec = @intCast(isize, ts % 1000000000), |
| 95 | }; |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | pub fn clock_gettime(clock_id: i32, tp: *timespec) errno_t { |
| 100 | var ts: timestamp_t = undefined; |
| 101 | const err = clock_time_get(@bitCast(u32, clock_id), 1, &ts); |
| 102 | if (err != 0) { |
| 103 | return err; |
| 104 | } |
| 105 | tp.* = .{ |
| 106 | .tv_sec = @intCast(i64, ts / 1000000000), |
| 107 | .tv_nsec = @intCast(isize, ts % 1000000000), |
| 108 | }; |
| 109 | return 0; |
| 110 | } |