diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-10-08 05:34:45 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-10-08 05:34:45 +0000 |
commit | 00882bfe350ed172c5d19c1299b626671e70d194 (patch) | |
tree | 1bc2705872df4873012c83f1788204f0c4dcb883 /io.c | |
parent | e2d1e7cfe4873acb518a8265a222307a90d6298a (diff) | |
download | ruby-00882bfe350ed172c5d19c1299b626671e70d194.tar.gz |
* io.c (io_write): must check returned value from fwrite() before
test with ferror(). (ruby-bugs-ja:PR#350)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -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); |