Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Errno#errno_message getter #6702

Merged
merged 6 commits into from Jan 2, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/errno.cr
Expand Up @@ -204,8 +204,8 @@ class Errno < Exception
# Returns the numeric value of errno.
getter errno : Int32

# Creates a new Errno with the given message. The message will
# have concatenated the message denoted by `Errno#value`.
# Creates a new `Errno` with the given message. The message will
# have concatenated the error message denoted by *errno*.
#
# Typical usage:
#
Expand All @@ -217,7 +217,12 @@ class Errno < Exception
# ```
def initialize(message, errno = Errno.value)
@errno = errno
super "#{message}: #{String.new(LibC.strerror(errno))}"
super "#{message}: #{Errno.error(errno)}"
end

# Returns the error message denoted by *errno*.
def self.error(errno = Errno.value)
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
String.new(LibC.strerror(errno))
end

# Returns the value of libc's errno.
Expand All @@ -232,7 +237,7 @@ class Errno < Exception
LibC.__error.value
{% elsif flag?(:win32) %}
ret = LibC._get_errno(out errno)
raise Errno.new("get_errno", ret) unless ret == 0
raise Errno.new("_get_errno", ret) unless ret == 0
errno
{% end %}
end
Expand All @@ -249,7 +254,7 @@ class Errno < Exception
LibC.__error.value = value
{% elsif flag?(:win32) %}
ret = LibC._set_errno(value)
raise Errno.new("set_errno", ret) unless ret == 0
raise Errno.new("_set_errno", ret) unless ret == 0
value
{% end %}
end
Expand Down