summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016-02-10 13:51:05 -0500
committerRich Felker <dalias@aerifal.cx>2016-02-10 13:51:05 -0500
commit5a6e8d098abfef67028e6c3edbac39e0bbaf8bd8 (patch)
treeeaf074215e7add4ceef02eec8c7ce9cb96ff819b
parent869a9df5b5f7da57ebd86d146e25f78450678eeb (diff)
downloadmusl-5a6e8d098abfef67028e6c3edbac39e0bbaf8bd8.tar.gz
fix failed write reporting by fwrite in line-buffered mode
when a write error occurred while flushing output due to a newline, fwrite falsely reported all bytes up to and including the newline as successfully written. in general, due to buffering such "spurious success" returns are acceptable for stdio; however for line-buffered mode it was subtly wrong. errors were still visible via ferror() or as a short-write return if there was more data past the newline that should have been written, but since the contract for line-buffered mode is that everything up through the newline be written out immediately, a discrepency was observable in the actual file contents.
-rw-r--r--src/stdio/fwrite.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/stdio/fwrite.c b/src/stdio/fwrite.c
index 81ec271e..fa30c0d3 100644
--- a/src/stdio/fwrite.c
+++ b/src/stdio/fwrite.c
@@ -13,8 +13,8 @@ size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f)
/* Match /^(.*\n|)/ */
for (i=l; i && s[i-1] != '\n'; i--);
if (i) {
- if (f->write(f, s, i) < i)
- return i;
+ size_t n = f->write(f, s, i);
+ if (n < i) return n;
s += i;
l -= i;
}