Module: OS::Mac::FFI Private

Extended by:
NativeLibrary
Defined in:
os/mac/ffi.rb,
os/mac/ffi/dyld.rb,
os/mac/ffi/xattr.rb,
os/mac/ffi/foundation.rb,
os/mac/ffi/objective_c.rb,
os/mac/ffi/native_library.rb,
os/mac/ffi/core_foundation.rb,
os/mac/ffi/launch_services.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Wrapping module for FFI calls to system libraries.

Defined Under Namespace

Modules: CoreFoundation, Foundation, LaunchServices, NativeLibrary, ObjectiveC

Class Method Summary collapse

Class Method Details

.copy_xattrs(source, destination) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



92
93
94
95
# File 'os/mac/ffi/xattr.rb', line 92

def self.copy_xattrs(source, destination)
  list_xattrs(destination).each { |attribute| remove_xattr(destination, attribute) }
  list_xattrs(source).each { |attribute| set_xattr(destination, attribute, get_xattr(source, attribute)) }
end

.dyld_shared_cache_contains_path(path) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

mach-o/dyld.h:

bool _dyld_shared_cache_contains_path(const char* path);

Parameters:

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'os/mac/ffi/dyld.rb', line 16

def self.dyld_shared_cache_contains_path(path)
  function(
    "_dyld_shared_cache_contains_path",
    [Fiddle::TYPE_CONST_STRING],
    Fiddle::TYPE_BOOL,
  ).call(path)
end

.get_xattr(path, attribute) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'os/mac/ffi/xattr.rb', line 41

def self.get_xattr(path, attribute)
  value_length = function(
    "getxattr",
    [
      Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_VOIDP,
      Fiddle::TYPE_SIZE_T, Fiddle::TYPE_UINT32_T, Fiddle::TYPE_INT
    ],
    Fiddle::TYPE_SSIZE_T,
  ).call(path, attribute, nil, 0, 0, 0)
  raise_xattr_error("getxattr", path, attribute) if value_length == -1
  return "" if value_length.zero?

  Fiddle::Pointer.malloc(value_length, Fiddle::RUBY_FREE) do |value|
    read_value_length = function(
      "getxattr",
      [
        Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_VOIDP,
        Fiddle::TYPE_SIZE_T, Fiddle::TYPE_UINT32_T, Fiddle::TYPE_INT
      ],
      Fiddle::TYPE_SSIZE_T,
    ).call(path, attribute, value, value_length, 0, 0)
    raise "Attributes changed during system call" if read_value_length != value_length

    value[0, read_value_length]
  end
end

.list_xattrs(path) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'os/mac/ffi/xattr.rb', line 19

def self.list_xattrs(path)
  names_length = function(
    "listxattr",
    [Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_VOIDP, Fiddle::TYPE_SIZE_T, Fiddle::TYPE_INT],
    Fiddle::TYPE_SSIZE_T,
  ).call(path, nil, 0, 0)
  raise_xattr_error("listxattr", path) if names_length == -1
  return [] if names_length.zero?

  Fiddle::Pointer.malloc(names_length, Fiddle::RUBY_FREE) do |names|
    read_names_length = function(
      "listxattr",
      [Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_VOIDP, Fiddle::TYPE_SIZE_T, Fiddle::TYPE_INT],
      Fiddle::TYPE_SSIZE_T,
    ).call(path, names, names_length, 0)
    raise "Attributes changed during system call" if read_names_length != names_length

    names[0, read_names_length].split("\0")
  end
end

.remove_xattr(path, attribute) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



82
83
84
85
86
87
88
89
# File 'os/mac/ffi/xattr.rb', line 82

def self.remove_xattr(path, attribute)
  result = function(
    "removexattr",
    [Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_INT],
    Fiddle::TYPE_INT,
  ).call(path, attribute, 0)
  raise_xattr_error("removexattr", path, attribute) unless result.zero?
end

.set_xattr(path, attribute, value) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



69
70
71
72
73
74
75
76
77
78
79
# File 'os/mac/ffi/xattr.rb', line 69

def self.set_xattr(path, attribute, value)
  result = function(
    "setxattr",
    [
      Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_CONST_STRING, Fiddle::TYPE_VOIDP,
      Fiddle::TYPE_SIZE_T, Fiddle::TYPE_UINT32_T, Fiddle::TYPE_INT
    ],
    Fiddle::TYPE_INT,
  ).call(path, attribute, value.empty? ? nil : Fiddle::Pointer[value], value.bytesize, 0, 0)
  raise_xattr_error("setxattr", path, attribute) unless result.zero?
end