authorgravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-04-19 14:53:58-05:00
committergravatar for tgschultz@gmail.comtgschultz <tgschultz@gmail.com> 2018-04-19 14:53:58-05:00
logca4053ba49d8bd171e592783c6024795c4794fda
treed368f3a35e41a2505cc8341286a2f7d0bba00a92
parent89eade0548c3afe8531fcbccc753c5c1e22f8e89

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


1 files changed, 7 insertions(+), 4 deletions(-)

std/os/time.zig+7-4
...@@ -152,7 +152,7 @@ pub const Timer = struct {...@@ -152,7 +152,7 @@ pub const Timer = struct {
152 // impossible here barring cosmic rays or other such occurances of152 // impossible here barring cosmic rays or other such occurances of
153 // incredibly bad luck.153 // incredibly bad luck.
154 //On Darwin: This cannot fail, as far as I am able to tell.154 //On Darwin: This cannot fail, as far as I am able to tell.
155 const TimerError = error{TimerUnsupported, UnexpectedErrnoValue};155 const TimerError = error{TimerUnsupported, Unexpected};
156 pub fn start() TimerError!Timer {156 pub fn start() TimerError!Timer {
157 var self: Timer = undefined;157 var self: Timer = undefined;
158 158
...@@ -177,14 +177,17 @@ pub const Timer = struct {...@@ -177,14 +177,17 @@ pub const Timer = struct {
177 // seccomp is going to block us it will at least do so consistently177 // seccomp is going to block us it will at least do so consistently
178 var ts: posix.timespec = undefined;178 var ts: posix.timespec = undefined;
179 var result = posix.clock_getres(monotonic_clock_id, &ts);179 var result = posix.clock_getres(monotonic_clock_id, &ts);
180 switch (posix.getErrno(result)) {180 var errno = posix.getErrno(result);
181 switch (errno) {
181 0 => {},182 0 => {},
182 posix.EINVAL => return error.TimerUnsupported,183 posix.EINVAL => return error.TimerUnsupported,
183 else => return error.UnexpectedErrnoValue,184 else => return std.os.unexpectedErrorPosix(errno),
184 }185 }
185 self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);186 self.resolution = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
187
186 result = posix.clock_gettime(monotonic_clock_id, &ts);188 result = posix.clock_gettime(monotonic_clock_id, &ts);
187 if (posix.getErrno(result) != 0) return error.UnexpectedErrnoValue;189 errno = posix.getErrno(result);
190 if (errno != 0) return std.os.unexpectedErrorPosix(errno);
188 self.start_time = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);191 self.start_time = u64(ts.tv_sec) * u64(ns_per_s) + u64(ts.tv_nsec);
189 },192 },
190 Os.macosx, Os.ios => {193 Os.macosx, Os.ios => {