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/app_kit.rb,
os/mac/ffi/libproc.rb,
os/mac/ffi/security.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: AppKit, CoreFoundation, Foundation, LaunchServices, LibProc, NativeLibrary, ObjectiveC, Security

Constant Summary collapse

FINDER_TAGS_XATTR =

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

"com.apple.metadata:_kMDItemUserTags"

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:



95
96
97
98
99
100
101
# File 'os/mac/ffi/xattr.rb', line 95

def self.copy_xattrs(source, destination)
  kept_attributes, stale_attributes = list_xattrs(destination).partition { it == FINDER_TAGS_XATTR }
  stale_attributes.each { |attribute| remove_xattr(destination, attribute) }
  (list_xattrs(source) - kept_attributes).each do |attribute|
    set_xattr(destination, attribute, get_xattr(source, attribute))
  end
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:



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

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:



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

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:



85
86
87
88
89
90
91
92
# File 'os/mac/ffi/xattr.rb', line 85

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:



72
73
74
75
76
77
78
79
80
81
82
# File 'os/mac/ffi/xattr.rb', line 72

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