[BUG] File#rewind, File#syswrite, File#pos on Cygwin build

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default [BUG] File#rewind, File#syswrite, File#pos on Cygwin build

    On the cygwin build of ruby v1.8.0, I have encountered a strange bug
    when using rewind, syswrite and pos. If you open a file in read/write
    mode, read the contents, rewind, syswrite some data, then File#pos
    always seems to return zero. This does not happen if you use the
    windows build, or you replace 'syswrite' with 'write'.

    e.g:

    $ cat syswrite.rb
    #!/bin/ruby

    testStr = "hello\nthis is some example text\nblah blah blah"

    # read it, rewind, then write it back again
    File.open("out.txt", 'r+') do |file|
    file.readlines
    file.rewind
    bytes = file.syswrite(testStr)
    puts "#{bytes} bytes written"
    puts "Now at position #{file.pos}"
    end

    $ ls > out.txt

    $ syswrite.rb
    46 bytes written
    Now at position 0
    Alan Davies Guest

  2. Similar Questions and Discussions

    1. problem in binding xml file data to datagrid xml file isgenerated through JSP file
      problem it that i am creating xml file using JSP file and i want to bind DataGrid with xml file data that is created using JSP but it will not Bind...
    2. File Viewer / Bloated file sizes / What is the best file format?
      I would like to find a viewer capable of looking at the main Adobe formats as well as the standard formats such as JPG and WMF ... but yet the only...
    3. File::Glob can't load module [cygwin], perl-5.8.4 9 (newbie)
      I am playing with compiling Perl 5.8.4 under cygwin. Can anyone help me fix the error I seem not get past? ../perl harness Can't load module...
    4. Build pdf file?
      Hello all. My brother would like to create a website that high school math teachers could use. They would come to the web site and say "I'd like...
    5. Confused about locking a file via file.flock(File::LOCK_EX)
      I am writing a ruby appl under AIX where I need to update the /etc/hosts table. I would like to make sure that during my update nobody else can...
  3. #2

    Default Re: [BUG] File#rewind, File#syswrite, File#pos on Cygwin build

    >>>>> "A" == Alan Davies <NOSPAMcs96and@yahoo.co.ukNOSPAM> writes:

    A> On the cygwin build of ruby v1.8.0, I have encountered a strange bug
    A> when using rewind, syswrite and pos. If you open a file in read/write
    A> mode, read the contents, rewind, syswrite some data, then File#pos
    A> always seems to return zero. This does not happen if you use the
    A> windows build, or you replace 'syswrite' with 'write'.

    try to add a flush

    A> File.open("out.txt", 'r+') do |file|
    A> file.readlines
    A> file.rewind
    A> bytes = file.syswrite(testStr)

    file.flush

    A> puts "#{bytes} bytes written"
    A> puts "Now at position #{file.pos}"
    A> end


    Guy Decoux



    ts Guest

  4. #3

    Default Re: [BUG] File#rewind, File#syswrite, File#pos on Cygwin build


    "Alan Davies" <NOSPAMcs96and@yahoo.co.ukNOSPAM> schrieb im Newsbeitrag
    news:3fba526d@primark.com...
    > On the cygwin build of ruby v1.8.0, I have encountered a strange bug
    > when using rewind, syswrite and pos. If you open a file in read/write
    > mode, read the contents, rewind, syswrite some data, then File#pos
    > always seems to return zero. This does not happen if you use the
    > windows build, or you replace 'syswrite' with 'write'.
    "Do not mix with other methods that write to ios or you may get
    unpredictable results."
    [url]http://www.rubycentral.com/book/ref_c_io.html#IO.syswrite[/url]

    robert

    Robert Klemme Guest

  5. #4

    Default Re: [BUG] File#rewind, File#syswrite, File#pos on Cygwin build

    >>>>> "R" == Robert Klemme <bob.news@gmx.net> writes:

    R> "Do not mix with other methods that write to ios or you may get
    R> unpredictable results."
    R> [url]http://www.rubycentral.com/book/ref_c_io.html#IO.syswrite[/url]

    No, no.

    moulon% cat b.rb
    #!/usr/bin/ruby
    testStr = "hello\nthis is some example text\nblah blah blah"

    File.open("out.txt", 'r+') do |file|
    file.readlines
    puts "Now at position #{file.pos}"
    file.rewind
    puts "Now at position #{file.pos}"
    bytes = file.syswrite(testStr)
    puts "#{bytes} bytes written"
    puts "Now at position #{file.pos}"
    end
    moulon%

    moulon% ruby -v b.rb
    ruby 1.8.0 (2003-08-04) [sparc-solaris2.7]
    Now at position 3330
    Now at position 0
    46 bytes written
    Now at position 46
    moulon%

    the problem is in cygwin and linux ...



    Guy Decoux


    ts Guest

  6. #5

    Default Re: [BUG] File#rewind, File#syswrite, File#pos on Cygwin build

    ts wrote:
    > the problem is in cygwin and linux ...
    Can we get this fixed in 1.8.1 then?
    Alan Davies Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139