This is the appropriate place to put a link to this pair of classics on API design:
"How Do I Make This Hard to Misuse?" https://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html
"What If I Don't Actually Like My Users?" https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html
gets(), on the other hand, that is "horrendous".
But yes, gets is worse.
If there is no fixed relationship between the two, then that makes sense; but in this case there is a very simple and well-defined relationship between them. But to specify two lengths which must always agree; and if not, then what? You've effectively invented an additional artificial error condition, an additional branch, and burdened all the callers up the chain to do something, which is a treacherous path to complexity and the production of even more bugs.
Or are you just preaching the same mindless idiocy that lead to Microsoft's memcpy_s() (the "s" is for "stupid")?
(Honest questions in this it’s probably been 20 years since I did c)
The only reason for such a design I could think of is that the caller would be able to "detect" the overflow by comparing the returned value against the length of the buffer. But that is of course pointless, as the compiler is free to assume a buffer overflow cannot happen and thus optimize the check away...
I know, I know, C is low level and high performance, but surely in the year of our lord 2026, we could have come out with something simpler.
Horrendous is a strong word, you're right.
You could have come with something simpler in PL/I.