Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That’s exactly why you shouldn’t be using it: it does a very bad job at that, with behavior basically nobody wants.


But doing that if you have a large ancient C code base is a lot of work.

The reason for the existence of strlcpy isn’t that it is perfect, it’s that it’s the best option with good UX for integration into an existing C code base.


It's not, though. That's the point: the interface it provides is not very good. The API surface for "I have a string here and I want you to put it there but only the first n bytes" is well-defined and can be done in a much better way than what strlcpy does.


The API surface is "I have a string that I'm pretty sure will fit in this buffer, but if it doesn't I don't want to cough up control of my bootloader."


Yep and that space has space for improvement




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: