News for hackers. Stuff that matters.
Re:Designing a better strcpy by notaplumber on Saturday June 19, 2021 @08:06PM (#27565760)
> strlcpy... it’s not standard so it doesn’t satisfy 5 either.

It's a de facto standard supported on *BSD/macOS/Android/Linux(w/ musl libc) and a number of other commercial systems, it's also on track for standardization in POSIX (Issue 8).

https://www.austingroupbugs.net/view.php?id=986#c5050

https://www.opengroup.org/austin/docs/austin_1110.pdf

While it might not meet your arbitrary set of requirements, it already has decent adoption.

Re:Designing a better strcpy by saagarjha on Saturday June 19, 2021 @08:31PM (#27565881)
Yikes, I hope they don’t add it, that would make people want to use it even more. Given its surprising performance characteristics it’s usually not what you want.
Re:Designing a better strcpy by notaplumber on Saturday June 19, 2021 @09:20PM (#27566149)
It's looking very much like it will, but even if that wasn't the case, it's already widely in use and available in OS libc's and easy to copy, and it has been since OpenBSD first introduced it over 20 years ago. I also believe your performance claims are exaggerated.. and strlcpy does exactly what people want and expect in most scenarios.
Re:Designing a better strcpy by saagarjha on Saturday June 19, 2021 @09:31PM (#27566219)
I've seen a lot of strlcpys, and of that I think I have seen maybe one place where the return value was used. I think if you asked people why they used strlcpy, 95+% would say "security" and then list out the characteristics my strxcpy has, rather than "I want snprintf-like behavior with a size_t return" which is what strlcpy is. I would not be surprised if most people got the time complexity of the function incorrect because of this.
Re:Designing a better strcpy by asvitkine on Sunday June 20, 2021 @06:07AM (#27568652)
If the return value of strlcpy isn't used, the compiler can optimize the extra inefficiency away. (I don't know if any do, though.)

This is similar to how strlen(x)>0 calls get optimized to *x by clang and likely other compilers.