summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-08 05:34:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-08 05:34:45 +0000
commit00882bfe350ed172c5d19c1299b626671e70d194 (patch)
tree1bc2705872df4873012c83f1788204f0c4dcb883 /io.c
parente2d1e7cfe4873acb518a8265a222307a90d6298a (diff)
* 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.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/io.c b/io.c
index ccb00739c1..025e73d321 100644
--- a/io.c
+++ b/io.c
@@ -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);