| author | |
| committer | |
| log | bb0c5f7a2f816709a0ec5af7099057fdfbfad04a |
| tree | 3d5fb6d6a3de329464e56a5face49e785e76e807 |
| parent | 1fabd6bbf355eb6111c4ed88be97f1ec2bf7b1ae |
| parent | d395ed2d403aa0ff57c493052e3675de23292424 |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
wasi: implement timestamp2 files changed, 23 insertions(+), 0 deletions(-)
std/os/time.zig+13| ... | ... | @@ -7,6 +7,7 @@ const testing = std.testing; |
| 7 | 7 | const windows = std.os.windows; |
| 8 | 8 | const linux = std.os.linux; |
| 9 | 9 | const darwin = std.os.darwin; |
| 10 | const wasi = std.os.wasi; | |
| 10 | 11 | const posix = std.os.posix; |
| 11 | 12 | |
| 12 | 13 | pub const epoch = @import("epoch.zig"); |
| ... | ... | @@ -64,9 +65,21 @@ pub const milliTimestamp = switch (builtin.os) { |
| 64 | 65 | Os.windows => milliTimestampWindows, |
| 65 | 66 | Os.linux, Os.freebsd, Os.netbsd => milliTimestampPosix, |
| 66 | 67 | Os.macosx, Os.ios => milliTimestampDarwin, |
| 68 | Os.wasi => milliTimestampWasi, | |
| 67 | 69 | else => @compileError("Unsupported OS"), |
| 68 | 70 | }; |
| 69 | 71 | |
| 72 | fn milliTimestampWasi() u64 { | |
| 73 | var ns: wasi.timestamp_t = undefined; | |
| 74 | ||
| 75 | // TODO: Verify that precision is ignored | |
| 76 | const err = wasi.clock_time_get(wasi.CLOCK_REALTIME, 1, &ns); | |
| 77 | debug.assert(err == wasi.ESUCCESS); | |
| 78 | ||
| 79 | const ns_per_ms = 1000; | |
| 80 | return @divFloor(ns, ns_per_ms); | |
| 81 | } | |
| 82 | ||
| 70 | 83 | fn milliTimestampWindows() u64 { |
| 71 | 84 | //FileTime has a granularity of 100 nanoseconds |
| 72 | 85 | // and uses the NTFS/Windows epoch |
std/os/wasi/core.zig+10| ... | ... | @@ -1,18 +1,28 @@ |
| 1 | pub const clockid_t = u32; | |
| 1 | 2 | pub const errno_t = u16; |
| 2 | 3 | pub const exitcode_t = u32; |
| 3 | 4 | pub const fd_t = u32; |
| 4 | 5 | pub const signal_t = u8; |
| 6 | pub const timestamp_t = u64; | |
| 5 | 7 | |
| 6 | 8 | pub const ciovec_t = extern struct { |
| 7 | 9 | buf: [*]const u8, |
| 8 | 10 | buf_len: usize, |
| 9 | 11 | }; |
| 10 | 12 | |
| 13 | pub const CLOCK_REALTIME: clockid_t = 0; | |
| 14 | pub const CLOCK_MONOTONIC: clockid_t = 1; | |
| 15 | pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; | |
| 16 | pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; | |
| 17 | ||
| 11 | 18 | pub const SIGABRT: signal_t = 6; |
| 12 | 19 | |
| 13 | 20 | pub extern "wasi_unstable" fn args_get(argv: [*][*]u8, argv_buf: [*]u8) errno_t; |
| 14 | 21 | pub extern "wasi_unstable" fn args_sizes_get(argc: *usize, argv_buf_size: *usize) errno_t; |
| 15 | 22 | |
| 23 | pub extern "wasi_unstable" fn clock_res_get(clock_id: clockid_t, resolution: *timestamp_t) errno_t; | |
| 24 | pub extern "wasi_unstable" fn clock_time_get(clock_id: clockid_t, precision: timestamp_t, timestamp: *timestamp_t) errno_t; | |
| 25 | ||
| 16 | 26 | pub extern "wasi_unstable" fn environ_get(environ: [*]?[*]u8, environ_buf: [*]u8) errno_t; |
| 17 | 27 | pub extern "wasi_unstable" fn environ_sizes_get(environ_count: *usize, environ_buf_size: *usize) errno_t; |
| 18 | 28 |