rf-web/vendor/bundle/gems/ffi-1.11.1/samples/gettimeofday.rb

19 lines
534 B
Ruby
Raw Normal View History

2019-10-21 08:18:17 +00:00
require 'rubygems'
require 'ffi'
class Timeval < FFI::Struct
rb_maj, rb_min, rb_micro = RUBY_VERSION.split('.')
if rb_maj.to_i >= 1 && rb_min.to_i >= 9 || RUBY_PLATFORM =~ /java/
layout :tv_sec => :ulong, :tv_usec => :ulong
else
layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4
end
end
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :gettimeofday, [ :pointer, :pointer ], :int
end
t = Timeval.new
LibC.gettimeofday(t.pointer, nil)
puts "t.tv_sec=#{t[:tv_sec]} t.tv_usec=#{t[:tv_usec]}"