Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created March 10, 2012 16:09
Show Gist options
  • Save djberg96/2011890 to your computer and use it in GitHub Desktop.
Save djberg96/2011890 to your computer and use it in GitHub Desktop.
IO.fdwalk strangeness with ruby 1.9.3
require 'ffi'
class IO
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :fdwalk_c, :fdwalk, [:pointer, :pointer], :void
def self.fdwalk(lowfd)
func = FFI::Function.new(:int, [:pointer, :int]){ |cd, fd|
yield File.new(fd) if fd >= lowfd
}
ptr = FFI::MemoryPointer.new(:int)
ptr.write_int(lowfd)
fdwalk_c(func, ptr)
end
end
#IO.fdwalk(0){ |f| p f.fileno } # Works
IO.fdwalk(0){ } # fd error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment