summaryrefslogtreecommitdiff
path: root/src/stdio
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016-02-16 13:26:16 -0500
committerRich Felker <dalias@aerifal.cx>2016-02-16 13:26:16 -0500
commit10a17dfbad2c267d885817abc9c7589fc7ff630b (patch)
tree18813bb6680ec2140a595e2b7364d61626a5a1d2 /src/stdio
parent9c102700a7b9e743da692d3cb6bfa580fcdd4379 (diff)
downloadmusl-10a17dfbad2c267d885817abc9c7589fc7ff630b.tar.gz
fix assumption in fputs that fwrite returning 0 implies an error
internally, the idiom of passing nmemb=1 to fwrite and interpreting the return value of fwrite (which is necessarily 0 or 1) as failure/success is fairly widely used. this is not correct, however, when the size argument is unknown and may be zero, since C requires fwrite to return 0 in that special case. previously fwrite always returned nmemb on success, but this was changed for conformance with ISO C by commit 500c6886c654fd45e4926990fee2c61d816be197.
Diffstat (limited to 'src/stdio')
-rw-r--r--src/stdio/fputs.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/stdio/fputs.c b/src/stdio/fputs.c
index 4737f448..1cf344f2 100644
--- a/src/stdio/fputs.c
+++ b/src/stdio/fputs.c
@@ -3,7 +3,8 @@
int fputs(const char *restrict s, FILE *restrict f)
{
- return (int)fwrite(s, strlen(s), 1, f) - 1;
+ size_t l = strlen(s);
+ return (fwrite(s, 1, l, f)==l) - 1;
}
weak_alias(fputs, fputs_unlocked);