zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ca4053ba49d8bd171e592783c6024795c4794fda (tree)
parent 89eade0548c3afe8531fcbccc753c5c1e22f8e89
Author: tgschultz <tgschultz@gmail.com>
Date:   Thu, 19 Apr 2018 14:53:58 -0500

Use std.os.errorUnexpectedPosix if timer initialization encounters unexpected error

Diffstat:
Mstd/os/time.zig | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/std/os/time.zig b/std/os/time.zig @@ -152,7 +152,7 @@ pub const Timer = struct { // impossible here barring cosmic rays or other such occurances of // incredibly bad luck. //On Darwin: This cannot fail, as far as I am able to tell. - const TimerError = error{TimerUnsupported, UnexpectedErrnoValue}; + const TimerError = error{TimerUnsupported, Unexpected}; pub fn start() TimerError!Timer { var self: Timer = undefined; @@ -177,14 +177,17 @@ pub const Timer = struct { // seccomp is going to block us it will at least do so consistently var ts: posix.timespec = undefined; var result = posix.clock_getres(monotonic_clock_id, &ts); - switch (posix.getErrno(result)) { + var errno = posix.getErrno(result); + switch (errno) { 0 => {}, posix.EINVAL => return error.TimerUnsupported, - else => return error.UnexpectedErrnoValue, + else => return std.os.unexpectedErrorPosix(errno), } self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec); + result = posix.clock_gettime(monotonic_clock_id, &ts); - if (posix.getErrno(result) != 0) return error.UnexpectedErrnoValue; + errno = posix.getErrno(result); + if (errno != 0) return std.os.unexpectedErrorPosix(errno); self.start_time = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec); }, Os.macosx, Os.ios => {