Module: ProcessShared::Posix::Errno
- Extended by:
- FFI::Library
- Included in:
- LibC, Semaphore::Foreign, SharedMemory::Foreign
- Defined in:
- lib/process_shared/posix/errno.rb
Instance Method Summary collapse
-
#error_check(*syms, &is_err) ⇒ Object
Replace methods in
syms
with error checking wrappers that invoke the original method and raise a SystemCallError with the current errno if the return value is an error.
Instance Method Details
#error_check(*syms, &is_err) ⇒ Object
Replace methods in syms
with error checking wrappers that invoke the original method and raise a SystemCallError with the current errno if the return value is an error.
Errors are detected if the block returns true when called with the original method’s return value.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/process_shared/posix/errno.rb', line 18 def error_check(*syms, &is_err) unless block_given? is_err = lambda { |v| (v == -1) } end syms.each do |sym| method = self.method(sym) new_method_body = proc do |*args| ret = method.call(*args) if is_err.call(ret) raise SystemCallError.new("error in #{sym}", Errno.errno) else ret end end define_singleton_method(sym, &new_method_body) define_method(sym, &new_method_body) end end |