Hi all,

Just curious - why was Ruby's temporary file handling class
(tempfile.rb) written in pure Ruby instead of using the tmpfile()
function? That function appears to be supported on most platforms,
including MS Windows.

Are there file locking or threading issues I'm not aware of?

The tmpfile() function does have the advantage of deleting itself when
all references to it are gone, instead of waiting until the Ruby
process itself dies. Perhaps there's no real advantage to that,
though?

Like I said, not an issue, just curious.

Regards,

Dan

PS - Below is a simple version I created for Solaris (before I
realized how ubiquitous the tmpfile function was):

#include <ruby.h>
#include <stdio.h>

#define VERSION "0.0.1"

VALUE mSolaris, cTempfile;

/* :call-seq:
 *    Solaris::Tmpfile.new => file
 *
 * Creates a new, anonymous temporary file in your Tempfile::TMPDIR
directory,
 * or /tmp if that cannot be accessed. If your $TMPDIR environment
variable is
 * set, it will be used instead. If $TMPDIR is not writable by the
process, it
 * will resort back to Tempfile::TMPDIR or /tmp.
 */
static VALUE tempfile_init(VALUE self){
   VALUE v_args[1];

   v_args[0] = INT2FIX(fileno(tmpfile()));

   rb_call_super(1, v_args);
}

void Init_tempfile(){
   mSolaris  = rb_define_module("Solaris");
   cTempfile = rb_define_class_under(mSolaris, "Tempfile", rb_cFile);

   rb_define_method(cTempfile, "initialize", tempfile_init, 0);

   rb_define_const(cTempfile, "TMPDIR", rb_str_new2(P_tmpdir));
   rb_define_const(cTempfile, "VERSION", rb_str_new2(VERSION));
}