Problem subclassing IO and writing on Windows

From: Ara.T.Howard [mailto:Ara.T.Howard@noaa.gov]
Sent: Wednesday, October 12, 2005 2:26 PM
To: ruby-talk ML
Subject: Re: Problem subclassing IO and writing on Windows

<snip>

   def initialize *a, &b
     super *a
     binmode
     b and b.call
   end

That's not it. I didn't see that you have to pass the mode *twice* on
Windows:

# This works:
io = IO.new(File.open("test.txt", "wb+").fileno, "wb+")
io.write("hello")
io.close

# This fails:
io = IO.new(File.open("test.txt").fileno, "wb+")
io.write("hello")
io.close

iotest.rb:3:in `close': Bad file descriptor (Errno::EBADF)
        from iotest.rb:3

# This also fails:
io = IO.new(File.open("test.txt", "wb+").fileno)
io.write("hello")
io.close

C:\eclipse\workspace\ruby-foo\iostuff>ruby iotest.rb
iotest.rb:2:in `write': not opened for writing (IOError)
        from iotest.rb:2

I'll have to look at io.c now to see what's really going on. At least
it works now. :slight_smile:

Regards,

Dan

···

-----Original Message-----

Hi,

At Thu, 13 Oct 2005 05:44:49 +0900,
Berger, Daniel wrote in [ruby-talk:160270]:

I'll have to look at io.c now to see what's really going on. At least
it works now. :slight_smile:

On Windows, fcntl() can't tell in what mode a file descriptor
was opened. So the new mode is defaulted to read-only.

···

--
Nobu Nakada