diff options
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); |