3 ms·
The refusal of glibc (and I suppose, POSIX) to adopt strlcat/cpy is continually obnoxious. That said, if you actually need efficient string operations, you pro
by loeg 7y ago
The refusal of glibc (and I suppose, POSIX) to adopt strlcat/cpy is continually obnoxious.
That said, if you actually need efficient string operations, you probably want a Rope data structure rather than any libc primitive.
- Gibbon1 7y agoI've never used a rope library, but having read a few essaying on those I keep coming back to it. I also keep coming back to hiding implementation details behind closures. I'm likely not smart enough to understand why that's a bad idea tho.
- ncmncm 7y agostrlcat and strlcpy are not adopted because they are a really bad design. Using them correctly takes more code than not using them. In practice they are never used correctly, making them, an "attractive nuisance", a feature that causes more trouble than its absence.
- loeg 7y agoThis argument doesn't hold water. They're absolutely no worse than strcat/cpy and strncat/cpy, which glibc implements. I totally disagree with your premise that truncation is an incorrect use. In reality, the alternative to strlcpy/cat isn't "force programmers to write correct code," it's "programmers will just use the crappier available functions with even worse behavior on overrun."
- ncmncm 7y agoPerhaps you have some better reason why Posix has rejected it, again and again? Some sort of conspiracy is conceivable, but in service of what? I have seen much, much better designs, that take into account that these functions are rarely called in isolation. In those, calls cooperate with previous and subsequent calls to share the burdens of maintaining correctness and safety.
- brynet 7y agoPOSIX never rejected strlcpy/strlcat, because they were never submitted for inclusion. Also, POSIX doesn't control the str* namespace, ISO C does. Not that it matters, as it wasn't submitted there either. But that's beside the point. Every major OS's libc has an implementation of strlcpy/strlcat, and OpenBSD's can be readily lifted into a project's source tree as it is portable, a simple code search will reveal the breadth of adoption. The /only/ exception is glibc now. And glibc is not a standards committee, for years the primary objections came from one person. You're being dishonest. https://github.com/search?q=strlcpy&type=Code https://github.com/search?q=strlcpy&type=Code