# Ruby 1.9.1 mingw32 under Windows

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-1-mingw32-under-windows/180108>\
**Category:** Ruby\
**Created:** [December 11, 2009, 6:34pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-mingw32-under-windows/180108 "2009-12-11T18:34:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tandrei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b77776/32.png) [@tandrei](https://www.ruby-forum.com/u/tandrei)\
**Post date:** [December 11, 2009, 6:34pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-mingw32-under-windows/180108/1 "2009-12-11T18:34:39Z")

</div>

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 =/

---

<div class="post-metadata">

**Author:** ![tandrei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b77776/32.png) [@tandrei](https://www.ruby-forum.com/u/tandrei)\
**Post date:** [December 11, 2009, 8:14pm UTC](https://www.ruby-forum.com/t/ruby-1-9-1-mingw32-under-windows/180108/2 "2009-12-11T20:14:08Z")

</div>

On Dec 11, 2:34 pm, Andrei T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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:

> **[Ruby Issue Tracking System](https://redmine.ruby-lang.org/)**
>
> Redmine

[http://redmine.ruby-lang.org/projects/show/ruby-191](http://redmine.ruby-lang.org/projects/show/ruby-191)

---

<div class="post-metadata">

**Author:** ![tandrei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b77776/32.png) [@tandrei](https://www.ruby-forum.com/u/tandrei)\
**Post date:** [December 12, 2009, 5:03am UTC](https://www.ruby-forum.com/t/ruby-1-9-1-mingw32-under-windows/180108/3 "2009-12-12T05:03:12Z")

</div>

On Dec 11, 12:34 pm, Andrei T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

removed\_email\_address@domain.invalid
