summaryrefslogtreecommitdiff
path: root/lib/ffi-xattr/error.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ffi-xattr/error.rb')
-rw-r--r--lib/ffi-xattr/error.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/ffi-xattr/error.rb b/lib/ffi-xattr/error.rb
new file mode 100644
index 0000000..602053d
--- /dev/null
+++ b/lib/ffi-xattr/error.rb
@@ -0,0 +1,23 @@
+class Xattr # :nodoc: all
+ module Error
+ extend FFI::Library
+
+ ffi_lib "c"
+
+ attach_function :strerror_r, [:int, :pointer, :size_t], :int unless RUBY_PLATFORM =~ /mingw/
+
+ class << self
+ def last
+ errno = FFI.errno
+ ptr = FFI::MemoryPointer.new(:char, 256)
+ strerror_r(errno, ptr, 256)
+
+ [ ptr.read_string, errno ]
+ end
+
+ def check(int)
+ raise SystemCallError.new(*last) if int != 0
+ end
+ end
+ end
+end