diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | io.c | 10 |
2 files changed, 9 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Tue Oct 8 14:19:07 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> + + * io.c (io_write): must check returned value from fwrite() before + test with ferror(). (ruby-bugs-ja:PR#350) + Tue Oct 8 10:55:23 2002 Tanaka Akira <akr@m17n.org> * lib/prettyprint.rb (PrettyPrint.singleline_format): new method. @@ -366,17 +366,15 @@ io_write(io, str) ptr = RSTRING(str)->ptr; n = RSTRING(str)->len; - do { #ifdef __human68k__ + do { if (fputc(*ptr++, f) == EOF) { if (ferror(f)) rb_sys_fail(fptr->path); break; } - --n; + } while (--n > 0); #else - r = fwrite(ptr, 1, n, f); - ptr += r; - n -= r; + for (; (r = fwrite(ptr, 1, n, f)) < n; ptr += r, n -= r) { if (ferror(f)) { if (rb_io_wait_writable(fileno(f))) { clearerr(f); @@ -384,8 +382,8 @@ io_write(io, str) } rb_sys_fail(fptr->path); } + } #endif - } while (n > 0); n = ptr - RSTRING(str)->ptr; if (fptr->mode & FMODE_SYNC) { io_fflush(f, fptr); |