diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-25 03:06:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-25 03:06:12 +0000 |
commit | ac9d09ba3c73417a6a53e9683d433419ca15504a (patch) | |
tree | 541379cc6028304fe26a7fb97cd2b81d1fe61992 /io.c | |
parent | 9594c893f7c5940bbd4e08044eef6ff94ef27a97 (diff) | |
download | ruby-ac9d09ba3c73417a6a53e9683d433419ca15504a.tar.gz |
* io.c (rb_io_getline_1): enables limit even if rs is given.
[ruby-core:22434]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22610 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -2246,7 +2246,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io) GetOpenFile(io, fptr); rb_io_check_readable(fptr); - if (NIL_P(rs)) { + if (NIL_P(rs) && limit < 0) { str = read_all(fptr, 0, Qnil); if (RSTRING_LEN(str) == 0) return Qnil; } @@ -2258,24 +2258,26 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io) return rb_io_getline_fast(fptr, enc); } else { - int c, newline; - const char *rsptr; - long rslen; + int c, newline = -1; + const char *rsptr = 0; + long rslen = 0; int rspara = 0; int extra_limit = 16; - rslen = RSTRING_LEN(rs); - if (rslen == 0) { - rsptr = "\n\n"; - rslen = 2; - rspara = 1; - swallow(fptr, '\n'); - rs = 0; - } - else { - rsptr = RSTRING_PTR(rs); + if (!NIL_P(rs)) { + rslen = RSTRING_LEN(rs); + if (rslen == 0) { + rsptr = "\n\n"; + rslen = 2; + rspara = 1; + swallow(fptr, '\n'); + rs = 0; + } + else { + rsptr = RSTRING_PTR(rs); + } + newline = (unsigned char)rsptr[rslen - 1]; } - newline = (unsigned char)rsptr[rslen - 1]; /* MS - Optimisation */ enc = io_read_encoding(fptr); |