diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-30 14:38:26 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-11-30 14:38:26 +0000 |
commit | 05e5590ece1f0644d129a93801d711a9d298d02f (patch) | |
tree | 7fe8f7f73cb3c48272f5defa0a96cee10012fb31 /io.c | |
parent | a70f475dbbdd0e8f2b14d98aefc3d01fc5af3d17 (diff) |
* io.c (io_fread): need not to null terminate. [ruby-dev:24998]
* io.c (read_all): remove unnecessary rb_str_resize().
[ruby-dev:24996] (backported from CVS HEAD)
* io.c (io_readpartial): ditto.
* io.c (io_read): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -988,7 +988,6 @@ io_fread(ptr, len, fptr) } if (len == n) return 0; } - *ptr = '\0'; break; } *ptr++ = c; @@ -1064,7 +1063,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; @@ -1140,11 +1138,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); @@ -2184,14 +2185,12 @@ rb_io_sysread(argc, argv, io) TRAP_END; 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); |