aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-05-24 20:06:56 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-05-24 21:40:08 -0400
commit53d011fa1a7bfb2389e3677e1f6fcbe7a678e05f (patch)
tree6dc248d8606088f7a288c00f6ccef78290229cf4 /lib/std/os
parentc6e7d0fcfdf83531c5c931433528c540eee62e56 (diff)
downloadzig-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')
-rw-r--r--lib/std/os/bits/darwin.zig9
-rw-r--r--lib/std/os/windows.zig14
2 files changed, 16 insertions, 7 deletions
diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig
index 24f20b70ea..4581490e6f 100644
--- a/lib/std/os/bits/darwin.zig
+++ b/lib/std/os/bits/darwin.zig
@@ -1456,3 +1456,12 @@ pub const POLLHUP = 0x010;
pub const POLLNVAL = 0x020;
pub const POLLSTANDARD = POLLIN | POLLPRI | POLLOUT | POLLRDNORM | POLLRDBAND | POLLWRBAND | POLLERR | POLLHUP | POLLNVAL;
+
+pub const CLOCK_REALTIME = 0;
+pub const CLOCK_MONOTONIC = 6;
+pub const CLOCK_MONOTONIC_RAW = 4;
+pub const CLOCK_MONOTONIC_RAW_APPROX = 5;
+pub const CLOCK_UPTIME_RAW = 8;
+pub const CLOCK_UPTIME_RAW_APPROX = 9;
+pub const CLOCK_PROCESS_CPUTIME_ID = 12;
+pub const CLOCK_THREAD_CPUTIME_ID = 16;
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index ff10c08865..e1d54743ab 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -1193,23 +1193,23 @@ pub fn peb() *PEB {
/// Universal Time (UTC).
/// This function returns the number of nanoseconds since the canonical epoch,
/// which is the POSIX one (Jan 01, 1970 AD).
-pub fn fromSysTime(hns: i64) i64 {
- const adjusted_epoch = hns + std.time.epoch.windows * (std.time.ns_per_s / 100);
+pub fn fromSysTime(hns: i64) i128 {
+ const adjusted_epoch = @as(i128, hns + std.time.epoch.windows) * (std.time.ns_per_s / 100);
return adjusted_epoch * 100;
}
-pub fn toSysTime(ns: i64) i64 {
+pub fn toSysTime(ns: i128) i64 {
const hns = @divFloor(ns, 100);
- return hns - std.time.epoch.windows * (std.time.ns_per_s / 100);
+ return @intCast(i64, hns) - std.time.epoch.windows * (std.time.ns_per_s / 100);
}
-pub fn fileTimeToNanoSeconds(ft: FILETIME) i64 {
- const hns = @bitCast(i64, (@as(u64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime);
+pub fn fileTimeToNanoSeconds(ft: FILETIME) i128 {
+ const hns = (@as(i64, ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
return fromSysTime(hns);
}
/// Converts a number of nanoseconds since the POSIX epoch to a Windows FILETIME.
-pub fn nanoSecondsToFileTime(ns: i64) FILETIME {
+pub fn nanoSecondsToFileTime(ns: i128) FILETIME {
const adjusted = @bitCast(u64, toSysTime(ns));
return FILETIME{
.dwHighDateTime = @truncate(u32, adjusted >> 32),