Module: Xattr::Lib

Extended by:
FFI::Library
Defined in:
lib/ffi-xattr/linux_lib.rb,
lib/ffi-xattr/darwin_lib.rb,
lib/ffi-xattr/windows_lib.rb

Constant Summary collapse

XATTR_NOFOLLOW =
0x0001

Class Method Summary collapse

Class Method Details

.get(path, no_follow, key) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/ffi-xattr/linux_lib.rb', line 29

def get(path, no_follow, key)
  method = no_follow ? :lgetxattr : :getxattr
  size = send(method, path, key, nil, 0)
  return unless size > 0

  str_ptr = FFI::MemoryPointer.new(:char, size)
  send(method, path, key, str_ptr, size)

  str_ptr.read_string(size)
end

.list(path, no_follow) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/ffi-xattr/linux_lib.rb', line 20

def list(path, no_follow)
  method = no_follow ? :llistxattr : :listxattr
  size = send(method, path, nil, 0)
  res_ptr = FFI::MemoryPointer.new(:pointer, size)
  send(method, path, res_ptr, size)

  res_ptr.read_string(size).split("\000")
end

.remove(path, no_follow, key) ⇒ Object



45
46
47
48
# File 'lib/ffi-xattr/linux_lib.rb', line 45

def remove(path, no_follow, key)
  method = no_follow ? :lremovexattr : :removexattr
  Error.check send(method, path, key)
end

.set(path, no_follow, key, value) ⇒ Object



40
41
42
43
# File 'lib/ffi-xattr/linux_lib.rb', line 40

def set(path, no_follow, key, value)
  method = no_follow ? :lsetxattr : :setxattr
  Error.check send(method, path, key, value, value.bytesize, 0)
end