Module: FFI::Platform

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/platform.rb

Overview

This module defines different constants and class methods to play with various platforms.

Constant Summary collapse

OS =
case RbConfig::CONFIG['host_os'].downcase
when /linux/
  "linux"
when /darwin/
  "darwin"
when /freebsd/
  "freebsd"
when /netbsd/
  "netbsd"
when /openbsd/
  "openbsd"
when /dragonfly/
  "dragonflybsd"
when /sunos|solaris/
  "solaris"
when /mingw|mswin/
  "windows"
else
  RbConfig::CONFIG['host_os'].downcase
end
OSVERSION =
RbConfig::CONFIG['host_os'].gsub(/[^\d]/, '').to_i
CPU =
RbConfig::CONFIG['host_cpu']
ARCH =
case CPU.downcase
when /amd64|x86_64|x64/
  "x86_64"
when /i\d86|x86|i86pc/
  "i386"
when /ppc64|powerpc64/
  "powerpc64"
when /ppc|powerpc/
  "powerpc"
when /sparcv9|sparc64/
  "sparcv9"
when /arm64|aarch64/  # MacOS calls it "arm64", other operating systems "aarch64"
  "aarch64"
when /^arm/
  if OS == "darwin"   # Ruby before 3.0 reports "arm" instead of "arm64" as host_cpu on darwin
    "aarch64"
  else
    "arm"
  end
else
  RbConfig::CONFIG['host_cpu']
end
LIBPREFIX =
case OS
when /windows|msys/
  ''
when /cygwin/
  'cyg'
else
  'lib'
end
LIBSUFFIX =
case OS
when /darwin/
  'dylib'
when /linux|bsd|solaris/
  'so'
when /windows|cygwin|msys/
  'dll'
else
  # Punt and just assume a sane unix (i.e. anything but AIX)
  'so'
end
LIBC =
if IS_WINDOWS
  crtname = RbConfig::CONFIG["RUBY_SO_NAME"][/msvc\w+/] || 'ucrtbase'
  "#{crtname}.dll"
elsif IS_GNU
  GNU_LIBC
elsif OS == 'cygwin'
  "cygwin1.dll"
elsif OS == 'msys'
  # Not sure how msys 1.0 behaves, tested on MSYS2.
  "msys-2.0.dll"
else
  "#{LIBPREFIX}c.#{LIBSUFFIX}"
end
LITTLE_ENDIAN =
1234
BIG_ENDIAN =
4321
BYTE_ORDER =
[0x12345678].pack("I") == [0x12345678].pack("N") ? BIG_ENDIAN : LITTLE_ENDIAN

Class Method Summary collapse

Class Method Details

.bsd?Boolean

Test if current OS is a *BSD (include MAC)

Returns:

  • (Boolean)


156
157
158
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/platform.rb', line 156

def self.bsd?
  IS_BSD
end

.mac?Boolean

Test if current OS is Mac OS

Returns:

  • (Boolean)


168
169
170
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/platform.rb', line 168

def self.mac?
  IS_MAC
end

.solaris?Boolean

Test if current OS is Solaris (Sun OS)

Returns:

  • (Boolean)


174
175
176
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/platform.rb', line 174

def self.solaris?
  IS_SOLARIS
end

.unix?Boolean

Test if current OS is a unix OS

Returns:

  • (Boolean)


180
181
182
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/platform.rb', line 180

def self.unix?
  !IS_WINDOWS
end

.windows?Boolean

Test if current OS is Windows

Returns:

  • (Boolean)


162
163
164
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/ffi-1.15.5/lib/ffi/platform.rb', line 162

def self.windows?
  IS_WINDOWS
end