From: nobu.nokada@... Date: 2004-11-15T10:21:13+09:00 Subject: Re: Win32, file descriptors and rb_io_check_writable() 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); > } -- Nobu Nakada