Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created December 13, 2011 20:50
Show Gist options
  • Save djberg96/1473825 to your computer and use it in GitHub Desktop.
Save djberg96/1473825 to your computer and use it in GitHub Desktop.
Trying to get sysctlbyname working with ffi
require 'ffi'
class Foo
extend FFI::Library
ffi_lib('c')
attach_function :sysctlbyname,
[:string, :pointer, :pointer, :pointer, :size_t],
:int
def self.freq
ptr = FFI::MemoryPointer.new(:int)
size = FFI::MemoryPointer.new(:int)
if sysctlbyname("hw.cpufrequency", ptr, size, nil, 0) < 0
raise "sysctlbyname function failed"
end
p ptr.read_int # => 0 ?
end
end
Foo.freq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment