Created
December 13, 2011 20:50
-
-
Save djberg96/1473825 to your computer and use it in GitHub Desktop.
Trying to get sysctlbyname working with ffi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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