diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | io.c | 13 |
2 files changed, 17 insertions, 7 deletions
@@ -1,3 +1,14 @@ +Tue Nov 30 23:38:18 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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. + Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> * ext/stringio/stringio.c (strio_write): insufficiently filled string @@ -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); |