Skip to content

Commit

Permalink
Use WinError instead of Errno
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Dec 22, 2017
1 parent d18942a commit a255c87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/crystal/system/win32/time.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "c/winbase"
require "winerror"

module Crystal::System::Time
# Win32 epoch is 1601-01-01 00:00:00 UTC
Expand All @@ -13,7 +14,7 @@ module Crystal::System::Time
# TODO: For now, this method returns the UTC offset currently in place, ignoring *seconds*.
def self.compute_utc_offset(seconds : Int64) : Int32
ret = LibC.GetTimeZoneInformation(out zone_information)
raise Errno.new("GetTimeZoneInformation") if ret == -1
raise WinError.new("GetTimeZoneInformation") if ret == -1

zone_information.bias.to_i32 * -60
end
Expand All @@ -31,15 +32,15 @@ module Crystal::System::Time
@@performance_frequency : Int64 = begin
ret = LibC.QueryPerformanceFrequency(out frequency)
if ret == 0
raise Errno.new("QueryPerformanceFrequency")
raise WinError.new("QueryPerformanceFrequency")
end

frequency
end

def self.monotonic : {Int64, Int32}
if LibC.QueryPerformanceCounter(out ticks) == 0
raise Errno.new("QueryPerformanceCounter")
raise WinError.new("QueryPerformanceCounter")
end

{ticks / @@performance_frequency, (ticks.remainder(NANOSECONDS_PER_SECOND) * NANOSECONDS_PER_SECOND / @@performance_frequency).to_i32}
Expand Down
2 changes: 2 additions & 0 deletions src/winerror.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "c/winapi"

class WinError < Errno
# NOTE: `get_last_error` must be called BEFORE an instance of this class
# is malloced as it would change the "last error" to SUCCESS
Expand Down

0 comments on commit a255c87

Please sign in to comment.