summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-28 14:36:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-28 14:36:38 +0000
commitb961db7587376bf451775d3654c19a9da5d3a73d (patch)
tree75839e32cf450db7e3213b04749658e12553b8c3 /io.c
parent343f505fb8a6162d2a3ecbef360813eec81f221c (diff)
* 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
Diffstat (limited to 'io.c')
-rw-r--r--io.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/io.c b/io.c
index 9e3d77a..5693aba 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