class FFI::DynamicLibrary
def self.load_library(name, flags)
def self.load_library(name, flags) if name == FFI::CURRENT_PROCESS FFI::DynamicLibrary.open(nil, RTLD_LAZY | RTLD_LOCAL) else flags ||= RTLD_LAZY | RTLD_LOCAL libnames = (name.is_a?(::Array) ? name : [name]) libnames = libnames.map(&:to_s).map { |n| [n, FFI.map_library_name(n)].uniq }.flatten.compact errors = [] libnames.each do |libname| lib = try_load(libname, flags, errors) return lib if lib unless libname.start_with?("/") SEARCH_PATH.each do |prefix| path = "#{prefix}/#{libname}" if File.exist?(path) lib = try_load(path, flags, errors) return lib if lib end end end end raise LoadError, [*errors, SEARCH_PATH_MESSAGE].join(".\n") end end