summaryrefslogtreecommitdiff
path: root/ext/stringio
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-10 08:54:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-10 08:54:56 +0000
commitba18b0c6cbcfd9afed3684cf667a9503d65d5ca1 (patch)
tree73246f663869fd22c0b0e17e258a8ea1f8d8ed89 /ext/stringio
parentf449c04a3648f56a535399d4108b738e36059455 (diff)
* ext/stringio/stringio.c (strio_read): do not set EOF flag when
requested length is zero. [ruby-dev:22214] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio')
-rw-r--r--ext/stringio/stringio.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index f94c860728..2d0229acca 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -836,12 +836,12 @@ strio_read(argc, argv, self)
{
struct StringIO *ptr = readable(StringIO(self));
VALUE str;
- long len;
+ long len, olen;
switch (argc) {
case 1:
if (!NIL_P(argv[0])) {
- len = NUM2LONG(argv[0]);
+ len = olen = NUM2LONG(argv[0]);
if (len < 0) {
rb_raise(rb_eArgError, "negative length %ld given", len);
}
@@ -856,6 +856,7 @@ 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) {
if (ptr->flags & STRIO_EOF) return Qnil;
@@ -868,7 +869,7 @@ 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);
- ptr->flags |= STRIO_EOF;
+ if (olen) ptr->flags |= STRIO_EOF;
}
else {
ptr->pos += RSTRING(str)->len;