Ruby 1.9.1 mingw32 under Windows

I’ve tried using ruby 1.9.1 compiled with mingw32 and had the following
error:

f = File.open(‘C:/1.tst’, ‘w’) => #<File:C:/1.tst>
f.truncate(0) => 0
f.truncate(10)
Errno::EINVAL: Invalid argument - C:/1.tst
from (irb):4:in truncate' from (irb):4 from D:/Tuzhilin/ruby/ruby-1.9.1-p129-i386-mingw32/bin/irb.bat:20:in

This code works perfectly on win32 version or 1.8.6-mingw32,
1.8.7-mingw32. Furthermore, this:

File.truncate(‘C:/1.tst’, 10) => 0

works perfect as well.

Tried different builds of 1.9.1 and different versions of mingw32 gcc
compiler, no use =/

On Dec 11, 2:34 pm, Andrei T. [email protected] wrote:

D:/Tuzhilin/ruby/ruby-1.9.1-p129-i386-mingw32/bin/irb.bat:20:in `’

This code works perfectly on win32 version or 1.8.6-mingw32,
1.8.7-mingw32. Furthermore, this:

File.truncate(‘C:/1.tst’, 10) => 0

works perfect as well.

Tried different builds of 1.9.1 and different versions of mingw32 gcc
compiler, no use =/

If you believe this is a bug of Ruby, please test latest 1.9.1
patchlevel (243 or 376) and report it to Redmine:

http://redmine.ruby-lang.org/projects/show/ruby-191

On Dec 11, 12:34 pm, Andrei T. [email protected] wrote:

D:/Tuzhilin/ruby/ruby-1.9.1-p129-i386-mingw32/bin/irb.bat:20:in `’

Posted viahttp://www.ruby-forum.com/.

You are not using truncate correctly.

  1. Opening a file for “w” automatically truncates the file!

From the document from File#truncate:

truncate(file_name, integer)
Truncates the file file_name to be at most integer bytes long. Not
available on all platforms.

f = File.new(“out”, “w”)
f.write(“1234567890”) #=> 10
f.close #=> nil
File.truncate(“out”, 5) #=> 0
File.size(“out”) #=> 5
#############################################################################

I did the following experiment in irb

irb(main):032:0> f = File.new “out”, “w” => #<File:out>
irb(main):033:0> f.write(“1234567890”) =>
10
irb(main):034:0> f.close => nil

irb(main):035:0> File.truncate “out”, 5 =>
0
irb(main):036:0> File.size “out” =>
5

irb(main):037:0> File.truncate “out”, 6 =>
0
irb(main):038:0> File.size “out” =>
6

irb(main):039:0> File.truncate “out”, 0 =>
0
irb(main):040:0> File.size “out” =>
0

irb(main):041:0> File.truncate “out”, 10 =>
0
irb(main):042:0> File.size “out” => 10

So it appears that truncate adds non-printable characters if the file
originally contained fewer characters than specified.

when displayed in the “vim” editor, each added character looks like
this ‘^@’

It has been my humbling experience that when I thought I found a bug
in the code, the bug was me.

[email protected]