Created
March 10, 2012 16:09
-
-
Save djberg96/2011890 to your computer and use it in GitHub Desktop.
IO.fdwalk strangeness with ruby 1.9.3
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 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