From: Daniel Berger Date: 2009-08-01T11:54:23+09:00 Subject: JRuby, ffi, bad file descriptor Hi, JRuby 1.3.1 OS X 10.4.9 The following code is a port of a tempfile library I wrote. Ruby 1.8.6 and 1.9.x work alright, but with JRuby I'm getting a bad file descriptor error. Any ideas? Here's the code: 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 Result: temp.rb:42:in `initialize': Bad file descriptor - Bad file descriptor (Errno::EBADF) from temp.rb:56:in `new' from temp.rb:56 Regards, Dan