summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-10 16:05:13 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-10 16:05:13 +0000
commit64b6f2b2a14912f46c71377cb6281765072f6563 (patch)
treeed5844ad216921fc1bccab84b6735f17ca408c6d /io.c
parent9a10c9726115e7f3f31bb228ad41d5f17eecb5e5 (diff)
merge revision(s) 35594: [Backport #6422]
* io.c (io_unread): fix IO#pos with mode 'r' bug on Windows. If the end of reading buffer is CR, io_unread() needs to unread one more byte. [ruby-core:44874] [Bug #6401] * test/ruby/test_io_m17n.rb (TestIO_M17N#test_pos_with_buffer_end_cr): add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@35613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/io.c b/io.c
index bbe5da93e8..bdabcf78d3 100644
--- a/io.c
+++ b/io.c
@@ -302,6 +302,12 @@ io_unread(rb_io_t *fptr)
/* add extra offset for removed '\r' in rbuf */
extra_max = (long)(pos - fptr->rbuf.len);
p = fptr->rbuf.ptr + fptr->rbuf.off;
+
+ /* if the end of rbuf is '\r', rbuf doesn't have '\r' within rbuf.len */
+ if (*(fptr->rbuf.ptr + fptr->rbuf.capa - 1) == '\r') {
+ newlines++;
+ }
+
for (i = 0; i < fptr->rbuf.len; i++) {
if (*p == '\n') newlines++;
if (extra_max == newlines) break;