diff options
| author | tgschultz <tgschultz@gmail.com> | 2018-04-19 14:53:58 -0500 |
|---|---|---|
| committer | tgschultz <tgschultz@gmail.com> | 2018-04-19 14:53:58 -0500 |
| commit | ca4053ba49d8bd171e592783c6024795c4794fda (patch) | |
| tree | d368f3a35e41a2505cc8341286a2f7d0bba00a92 | |
| parent | 89eade0548c3afe8531fcbccc753c5c1e22f8e89 (diff) | |
| download | zig-ca4053ba49d8bd171e592783c6024795c4794fda.tar.gz zig-ca4053ba49d8bd171e592783c6024795c4794fda.zip | |
Use std.os.errorUnexpectedPosix if timer initialization encounters unexpected error
| -rw-r--r-- | std/os/time.zig | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/std/os/time.zig b/std/os/time.zig index 4f002de79e..8a906d7954 100644 --- 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 => { |
