From b961db7587376bf451775d3654c19a9da5d3a73d Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 28 Aug 2002 14:36:38 +0000 Subject: * io.c (appendline): data was lost when raw mode. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ io.c | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7dd1637c8f..73586e435a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Aug 28 23:34:32 2002 Nobuyoshi Nakada + + * io.c (appendline): data was lost when raw mode. + Wed Aug 28 19:12:46 2002 Nobuyoshi Nakada * ext/stringio/stringio.c (strio_initialize): RSTRING(mode)->ptr diff --git a/io.c b/io.c index 9e3d77aa49..5693aba842 100644 --- a/io.c +++ b/io.c @@ -727,14 +727,16 @@ appendline(fptr, delim, strp) if (pending > 0) { const char *p = READ_DATA_PENDING_PTR(f); const char *e = memchr(p, delim, pending); - long last = 0; + long last = 0, len = (c != EOF); if (e) pending = e - p + 1; + len += pending; if (!NIL_P(str)) { last = RSTRING(str)->len; - rb_str_resize(str, last + (c != EOF) + pending); + rb_str_resize(str, last + len); } else { - *strp = str = rb_str_new(0, (c != EOF) + pending); + *strp = str = rb_str_buf_new(len); + RSTRING(str)->len = len; } if (c != EOF) { RSTRING(str)->ptr[last++] = c; @@ -742,6 +744,16 @@ appendline(fptr, delim, strp) fread(RSTRING(str)->ptr + last, 1, pending, f); /* must not fail */ if (e) return delim; } + else if (c != EOF) { + if (!NIL_P(str)) { + char ch = c; + rb_str_buf_cat(str, &ch, 1); + } + else { + *strp = str = rb_str_buf_new(1); + RSTRING(str)->ptr[RSTRING(str)->len++] = c; + } + } rb_thread_wait_fd(fileno(f)); rb_io_check_closed(fptr); #else -- cgit v1.2.3