[PATCH] fputs return the number of characters written

Kacper Piwiński cosiekvfj@o2.pl
Mon Sep 20 18:15:52 GMT 2021


Sorry for the wrong indentation. Here is the same message:

I checked assembly and this operation is implemented with cmovbe. So quite fast.
What's funny overall code size stayed the same because compilation was able to reduce some code paths. 

(1)I agree that users should not depend on that if they want a portable program.
But people can target only glibc. Which is not a problem if they chose to?
(2)Yes that's a limitation. Do the same limitation apply to *printf?

So basically we should return strlen because :
1. we already compute it
3. string length is arguably more useful than constant 1
3. it is valid to return any non negative value for success
4. consistency:
- we already do that in puts
- *printf function family do that

Reason to not return strlen:
1. additional operation
2. arguably not that much useful
3. only INT_MAX

I see that I didn't change fputws and fputws_unlocked. So I will make a v2 with them also changed or
alternatively we can change puts to return 1 and also be consistent between *put*s functions.


More information about the Libc-alpha mailing list