summaryrefslogtreecommitdiff
path: root/ext/stringio/stringio.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-10 10:29:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-10 10:29:00 +0000
commitc5d4ee4a39df0f11a6ba98a8f5f19c9b64144baa (patch)
treeb3be9eff77a0d6e335414901285f8186a8dd8510 /ext/stringio/stringio.c
parent62b368dc4ae950b8218097cafc9fc4591e1093de (diff)
* ext/stringio/stringio.c (strio_read): set EOF flag at short read.
[ruby-dev:22223], [ruby-dev:22224] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r--ext/stringio/stringio.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 2d0229acca..88f6be42d3 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -857,10 +857,13 @@ strio_read(argc, argv, self)
/* fall through */
case 0:
olen = -1;
- len = RSTRING(ptr->string)->len - ptr->pos;
- if (len == 0 && ptr->pos == RSTRING(ptr->string)->len) {
+ len = RSTRING(ptr->string)->len;
+ if (len <= ptr->pos) {
if (ptr->flags & STRIO_EOF) return Qnil;
- ptr->flags |= STRIO_EOF;
+ len = 0;
+ }
+ else {
+ len -= ptr->pos;
}
break;
default:
@@ -869,11 +872,12 @@ strio_read(argc, argv, self)
str = rb_str_substr(ptr->string, ptr->pos, len);
if (NIL_P(str)) {
if (!(ptr->flags & STRIO_EOF)) str = rb_str_new(0, 0);
- if (olen) ptr->flags |= STRIO_EOF;
+ len = 0;
}
else {
- ptr->pos += RSTRING(str)->len;
+ ptr->pos += len = RSTRING(str)->len;
}
+ if (olen < 0 || olen > len) ptr->flags |= STRIO_EOF;
return str;
}