Sha256: aff59c39ccf6675de05ef3566e2c0fb245129f18d57c9b3e463bd22ca71320a1

Contents?: true

Size: 746 Bytes

Versions: 1

Compression:

Stored size: 746 Bytes

Contents

# frozen_string_literal: true
module Ethon

  # FFI Wrapper module for Libc.
  #
  # @api private
  module Libc
    extend FFI::Library
    ffi_lib 'c'

    # :nodoc:
    def self.windows?
      Gem.win_platform?
    end

    unless windows?
      fcg = FFI::ConstGenerator.new do |gen|
        gen.include 'unistd.h'
        %w[
          _SC_OPEN_MAX
        ].each do |const|
          ruby_name = const.sub(/^_SC_/, '').downcase.to_sym
          gen.const(const, "%d", nil, ruby_name, &:to_i)
        end
      end

      CONF = enum(*fcg.constants.map{|_, const|
        [const.ruby_name, const.converted_value]
      }.flatten)

      attach_function :sysconf, [CONF], :long
      attach_function :free, [:pointer], :void
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ethon-0.13.0 lib/ethon/libc.rb