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.
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);