Skip to content

Commit

Permalink
Fix error handling for LibC.clock_gettime(CLOCK_MONOTONIC) calls (#…
Browse files Browse the repository at this point in the history
…15309)

POSIX `clock_gettime` returns 0 on success and -1 on error. See https://man7.org/linux/man-pages/man3/clock_gettime.3.html#RETURN_VALUE
  • Loading branch information
compumike authored Dec 26, 2024
1 parent 9a218a0 commit eb56b55
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/crystal/system/unix/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ module Crystal::System::Time
nanoseconds = total_nanoseconds.remainder(NANOSECONDS_PER_SECOND)
{seconds.to_i64, nanoseconds.to_i32}
{% else %}
if LibC.clock_gettime(LibC::CLOCK_MONOTONIC, out tp) == 1
raise RuntimeError.from_errno("clock_gettime(CLOCK_MONOTONIC)")
end
ret = LibC.clock_gettime(LibC::CLOCK_MONOTONIC, out tp)
raise RuntimeError.from_errno("clock_gettime(CLOCK_MONOTONIC)") unless ret == 0
{tp.tv_sec.to_i64, tp.tv_nsec.to_i32}
{% end %}
end
Expand Down

0 comments on commit eb56b55

Please sign in to comment.