From: djberg96@... (Daniel Berger) Date: 2004-11-16T03:23:20+09:00 Subject: Re: Win32, file descriptors and rb_io_check_writable() nobu.nokada@softhome.net wrote in message news:<200411150121.iAF1LCVW027655@sharui.nakada.niregi.kanuma.tochigi.jp>... > Hi, > > At Sat, 13 Nov 2004 08:13:26 +0900, > Daniel Berger wrote in [ruby-talk:120101]: > > But, I cannot write to the filehandle: > > > > fh = File.nopen("C:\\somefile") > > fh.puts "Hello" > > > > test.rb:13:in `write': not opened for writing (IOError) > > from test.rb:13:in `puts' > > from test.rb:13 > > > > That error appears to be coming from the rb_io_check_writable() > > function, which in turn is checking the mode of the OpenFile struct > > defined in rubyio.h. > > > > How do I deal with this? Am I doing something wrong? Or would it > > take a modification of io.c for this to work? If so, what should be > > done? > > File#initialize accepts the mode in Fixnum. > > > // Convert HANDLE to file descriptor > > args[0] = UINT2NUM(_open_osfhandle((long)h,O_RDWR)); > switch (dwAccess & (GENERIC_READ|GENERIC_WRITE)) { > case 0: > args[1] = INT2FIX(0); > break; > case GENERIC_READ: > args[1] = INT2FIX(O_RDONLY); > break; > case GENERIC_WRITE: > args[1] = INT2FIX(O_WRONLY); > break; > default: > args[1] = INT2FIX(O_RDWR); > break; > } > > > > // Return a bonafide File object, based on the file descriptor > return rb_class_new_instance(2,args,klass); > > } This code does eliminate that error. However, it seems that the write operations still don't work properly. I can call fh.puts "hello" and, although no error is raised, nothing is actually written to the file. Any thoughts? Dan