1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2002-08-28 14:36:38 +00:00
parent 343f505fb8
commit b961db7587
2 changed files with 19 additions and 3 deletions

View file

@ -1,3 +1,7 @@
Wed Aug 28 23:34:32 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* io.c (appendline): data was lost when raw mode.
Wed Aug 28 19:12:46 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> Wed Aug 28 19:12:46 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* ext/stringio/stringio.c (strio_initialize): RSTRING(mode)->ptr * ext/stringio/stringio.c (strio_initialize): RSTRING(mode)->ptr

18
io.c
View file

@ -727,14 +727,16 @@ appendline(fptr, delim, strp)
if (pending > 0) { if (pending > 0) {
const char *p = READ_DATA_PENDING_PTR(f); const char *p = READ_DATA_PENDING_PTR(f);
const char *e = memchr(p, delim, pending); const char *e = memchr(p, delim, pending);
long last = 0; long last = 0, len = (c != EOF);
if (e) pending = e - p + 1; if (e) pending = e - p + 1;
len += pending;
if (!NIL_P(str)) { if (!NIL_P(str)) {
last = RSTRING(str)->len; last = RSTRING(str)->len;
rb_str_resize(str, last + (c != EOF) + pending); rb_str_resize(str, last + len);
} }
else { else {
*strp = str = rb_str_new(0, (c != EOF) + pending); *strp = str = rb_str_buf_new(len);
RSTRING(str)->len = len;
} }
if (c != EOF) { if (c != EOF) {
RSTRING(str)->ptr[last++] = c; RSTRING(str)->ptr[last++] = c;
@ -742,6 +744,16 @@ appendline(fptr, delim, strp)
fread(RSTRING(str)->ptr + last, 1, pending, f); /* must not fail */ fread(RSTRING(str)->ptr + last, 1, pending, f); /* must not fail */
if (e) return delim; 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_thread_wait_fd(fileno(f));
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
#else #else