From: Daniel Berger Date: 2009-08-03T21:21:01+09:00 Subject: Re: JRuby, ffi, bad file descriptor On Aug 2, 10:34 pm, Charles Oliver Nutter wrote: > Got the source of that temp.rb handy? It looks like it's passing a > bad/closed descriptor to IO.new or something... require 'ffi' class FileTemp < File extend FFI::Library attach_function 'fileno', [:pointer], :int attach_function 'fclose', [:pointer], :int attach_function 'mkstemp', [:string], :int attach_function 'tmpfile', [], :pointer attach_function 'tmpnam', [:string], :string attach_function 'umask', [:int], :int TMPDIR = ENV['TEMP'] || ENV['TMP'] || '/tmp' def initialize(delete = true, template = 'rb_file_temp_XXXXXX') @fptr = nil if delete @fptr = tmpfile() fd = fileno(@fptr) else begin omask = umask(077) fd = mkstemp(template) raise SystemCallError, 'mkstemp()' if fd < 0 ensure umask(omask) end end super(fd, 'wb+') end def close super fclose(@fptr) if @fptr end def self.temp_name TMPDIR + tmpnam(nil) << '.tmp' end end if $0 == __FILE__ fh = FileTemp.new fh.print 'hello' fh.close end