diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-30 09:36:39 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-30 09:36:39 +0000 |
commit | e6e84eab64ae594f78d21dbd07ba1d2de57168e3 (patch) | |
tree | a7c9c2ebf1a67ee682f5dac137632801984836fd /io.c | |
parent | ee6869c8d63643f2f3b198fa4ad8ed52a2744145 (diff) | |
download | ruby-e6e84eab64ae594f78d21dbd07ba1d2de57168e3.tar.gz |
* io.c (io_fread): need not to null terminate. [ruby-dev:24998]
* io.c (read_all): remove unnecessary rb_str_resize().
[ruby-dev:24996]
* io.c (io_readpartial): ditto.
* io.c (io_read): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -1009,7 +1009,6 @@ io_fread(ptr, len, fptr) } if (len == n) return 0; } - *ptr = '\0'; break; } *ptr++ = c; @@ -1086,7 +1085,6 @@ read_all(fptr, siz, str) n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr); rb_str_unlocktmp(str); if (n == 0 && bytes == 0) { - rb_str_resize(str,0); if (!fptr->f) break; if (feof(fptr->f)) break; if (!ferror(fptr->f)) break; @@ -1203,7 +1201,6 @@ io_readpartial(argc, argv, io) if (n < 0) { if (rb_io_wait_readable(fileno(fptr->f))) goto again; - rb_str_resize(str, 0); rb_sys_fail(fptr->path); } } @@ -1274,11 +1271,14 @@ io_read(argc, argv, io) n = io_fread(RSTRING(str)->ptr, len, fptr); rb_str_unlocktmp(str); if (n == 0) { - rb_str_resize(str,0); if (!fptr->f) return Qnil; - if (feof(fptr->f)) return Qnil; + if (feof(fptr->f)) { + rb_str_resize(str, 0); + return Qnil; + } if (len > 0) rb_sys_fail(fptr->path); } + rb_str_resize(str, n); RSTRING(str)->len = n; RSTRING(str)->ptr[n] = '\0'; OBJ_TAINT(str); @@ -2335,14 +2335,12 @@ rb_io_sysread(argc, argv, io) rb_str_unlocktmp(str); if (n == -1) { - rb_str_resize(str, 0); rb_sys_fail(fptr->path); } + rb_str_resize(str, n); if (n == 0 && ilen > 0) { - rb_str_resize(str, 0); rb_eof_error(); } - RSTRING(str)->len = n; RSTRING(str)->ptr[n] = '\0'; OBJ_TAINT(str); |