Skip to content

Instantly share code, notes, and snippets.

@jarib
Created March 31, 2011 00:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarib/895585 to your computer and use it in GitHub Desktop.
Save jarib/895585 to your computer and use it in GitHub Desktop.
uname() - ruby ffi
require 'ffi'
module Uname
extend FFI::Library
ffi_lib FFI::CURRENT_PROCESS
class UtsName < FFI::Struct
layout :sysname , [:char, 256],
:nodename, [:char, 256],
:release , [:char, 256],
:version , [:char, 256],
:machine , [:char, 256]
def to_hash
strings = values.map { |v| v.to_s }
Hash[members.zip strings]
end
end
attach_function :uname, [:pointer], :int
def self.get
un = UtsName.new
if uname(un) != 0
raise "failed" # check errno
end
un.to_hash
end
end
if __FILE__ == $0
p Uname.get
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment