What's "horrendous"? I don't see anything which stands out as being wrong. It specifies exactly the lengths of input and output.
gets(), on the other hand, that is "horrendous".
The thing that jumps out to me is that it returns “the size of the output data minus one” but if I’m passing in a pointer it’s on me to make sure there’s enough memory allocated isn’t it? So the caller must make sure it’s calculated this correctly - in which case why return the size? Taking the size as an argument could be safer as you’d be checking the caller calculated enough space too.
(Honest questions in this it’s probably been 20 years since I did c)
Perhaps I'm just used to having programmed in C# professionally for a little bit, but these sorts of APIs where you have to do a calculation to determine the destination buffer size make me feel like a caveman. A minuscule typo and you get a CVE like this.
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.
Even in C, if you have a function that takes an input buffer and output buffer of differing lengths, the right API has the caller pass both lengths.
But yes, gets is worse.