diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-05-24 20:06:56 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-05-24 21:40:08 -0400 |
| commit | 53d011fa1a7bfb2389e3677e1f6fcbe7a678e05f (patch) | |
| tree | 6dc248d8606088f7a288c00f6ccef78290229cf4 /lib/std/os.zig | |
| parent | c6e7d0fcfdf83531c5c931433528c540eee62e56 (diff) | |
| download | zig-53d011fa1a7bfb2389e3677e1f6fcbe7a678e05f.tar.gz zig-53d011fa1a7bfb2389e3677e1f6fcbe7a678e05f.zip | |
(breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.
nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.
calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).
implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index bc8803e3b0..22c884fce8 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3880,6 +3880,8 @@ pub fn dl_iterate_phdr( pub const ClockGetTimeError = error{UnsupportedClock} || UnexpectedError; +/// TODO: change this to return the timespec as a return value +/// TODO: look into making clk_id an enum pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { if (std.Target.current.os.tag == .wasi) { var ts: timestamp_t = undefined; @@ -3895,6 +3897,23 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { } return; } + if (std.Target.current.os.tag == .windows) { + if (clk_id == CLOCK_REALTIME) { + var ft: windows.FILETIME = undefined; + windows.kernel32.GetSystemTimeAsFileTime(&ft); + // FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch. + const ft64 = (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + const ft_per_s = std.time.ns_per_s / 100; + tp.* = .{ + .tv_sec = @intCast(i64, ft64 / ft_per_s) + std.time.epoch.windows, + .tv_nsec = @intCast(c_long, ft64 % ft_per_s) * 100, + }; + return; + } else { + // TODO POSIX implementation of CLOCK_MONOTONIC on Windows. + return error.UnsupportedClock; + } + } switch (errno(system.clock_gettime(clk_id, tp))) { 0 => return, |
