Actions
Bug #10039
closed"a+" mode for File.open doesn’t work
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
Backport:
Description
Hi there,
According to the documentation the "a+" file open mode should open a file:
Read-write, starts at end of file if file exists
However, it appears that the "a+" mode behaves exactly as "r+", i.e. the file pointer is placed at the beginning of the file instead of the end.
This example demonstrates the problem:
(288) [20:37:02 quintus@hades] /tmp/foobar
% cat test.txt
test
test2
(289) [20:37:07 quintus@hades] /tmp/foobar
% irb
irb(main):001:0> f = File.open("test.txt", "a+")
=> #<File:test.txt>
irb(main):002:0> f.pos
=> 0
irb(main):003:0> f.eof?
=> false
irb(main):004:0> f.read
=> "test\ntest2\n"
irb(main):005:0> f.pos
=> 10
irb(main):006:0> f.close
=> nil
irb(main):007:0>
The file position pointer should have been placed at the end of the file (i.e. position 10), not at the beginning (which is what "r+" is for).
Vale,
Quintus
Actions
Like0
Like0Like0Like0Like0Like0Like0