summaryrefslogtreecommitdiff
path: root/samples/gettimeofday.rb
diff options
context:
space:
mode:
Diffstat (limited to 'samples/gettimeofday.rb')
-rw-r--r--samples/gettimeofday.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/samples/gettimeofday.rb b/samples/gettimeofday.rb
new file mode 100644
index 0000000..f9835b4
--- /dev/null
+++ b/samples/gettimeofday.rb
@@ -0,0 +1,12 @@
+require 'ffi'
+class Timeval < FFI::Struct
+# layout :tv_sec => :ulong, :tv_usec => :ulong
+ layout :tv_sec, :ulong, 0, :tv_usec, :ulong, 4
+end
+module LibC
+ extend FFI::Library
+ 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]}"