public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
rubinius / kernel / core / errno.rb
100644 32 lines (24 sloc) 0.662 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# depends on: module.rb
 
##
# Interface to the C errno integer.
 
module Errno
 
  ##
  # Raises the appropriate SystemCallError exception with +additional+ as the
  # message. Equivalent to MRI's rb_sys_fail().
  #
  # Unlike rb_sys_fail(), handle does not raise an exception if errno is 0.
 
  def self.handle(additional = nil)
    err = Platform::POSIX.errno
    return if err == 0
 
    exc = Errno::Mapping[err]
    if exc
      msg = Platform::POSIX.strerror(err)
 
      if additional
        msg << " - " << additional
      end
 
      raise exc.new(msg, err)
    else
      raise "Unknown error: #{Platform::POSIX.strerror(err)} (#{err})"
    end
  end
end