Class: Sys::Proc::Helper::LibC

Inherits:
Object
  • Object
show all
Defined in:
lib/sys/proc/helper/lib_c.rb

Overview

System helper

Instance Method Summary collapse

Constructor Details

#initializeLibC

Returns a new instance of LibC.



14
15
16
# File 'lib/sys/proc/helper/lib_c.rb', line 14

def initialize
  @loadeds = {}
end

Instance Method Details

#available?(system = nil) ⇒ Boolean

Denote if libc is seen as availbale on targeted system

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sys/proc/helper/lib_c.rb', line 43

def available?(system = nil)
  begin
    dlopen(system)
  rescue Fiddle::DLError
    return false
  rescue KeyError
    return false
  end

  loadables[system] != nil
end

#dlopen(system = nil) ⇒ self

Open shared object (by system)

Parameters:

  • system (Symbol) (defaults to: nil)

Returns:

  • (self)


32
33
34
35
36
37
38
# File 'lib/sys/proc/helper/lib_c.rb', line 32

def dlopen(system = nil)
  system = (system.nil? ? Sys::Proc.system : system).to_sym

  loadeds[system] ||= Fiddle.dlopen(loadables.fetch(system))

  loadeds[system]
end

#loadablesHash

libc shared objects identified by system

Returns:

  • (Hash)


21
22
23
24
25
26
# File 'lib/sys/proc/helper/lib_c.rb', line 21

def loadables
  {
    linux_gnu: 'libc.so.6',
    freebsd: 'libc.so.7',
  }
end