Project

General

Profile

Bug #1909

Strange behavior IO#ungetc at the beginning of the stream

Added by tmat (Tomas Matousek) about 10 years ago. Updated over 8 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
Backport:
[ruby-core:24814]

Description

=begin
This works:
io = File.open("a.txt", "r+")
io.read(0)
p io.pos # => 0
io.ungetc(100)
p io.pos # => 0

while this doesn't:
io = File.open("a.txt", "r+")
p io.pos # => 0
io.ungetc(100) # => unread stream (IOError)

I would expect the first case to raise the same error as the second one since ungetc is supposed to shift the position back by 1 and we are at the beginning of the stream.

In ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32] neither case raises an exception, which is at least consistent but still weird.
=end

History

#1

Updated by mame (Yusuke Endoh) over 9 years ago

  • Status changed from Open to Rejected

=begin
Hi,

The 1.8 behavior depends on stdio.

In 1.9, pushing back behind the beginning should be considered
as implementation-defined. Not a bug.

--
Yusuke Endoh mame@tsg.ne.jp
=end

Also available in: Atom PDF