Issue #10039 has been reported by Marvin Glker.

----------------------------------------
Bug #10039: "a+" mode for File.open doesn¡Çt work
https://bugs.ruby-lang.org/issues/10039

* Author: Marvin Glker
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
Hi there,

According to [the documentation](http://www.ruby-doc.org/core-2.1.2/IO.html#method-c-new) 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



-- 
https://bugs.ruby-lang.org/