-
-
Notifications
You must be signed in to change notification settings - Fork 65
Implement strlcpy #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement strlcpy #561
Conversation
|
One good thing to check for is that a call to |
|
Yep, I checked |
|
I was going to do a review, but as was mentioned in chat it would be good to unconditionally do the strlen at the start and avoid doing it twice. My other feedback for now is that |
* Use sbc hl, hl rather than ld hl, 0 (carry was already cleared with xor a,a) * Unconditionally do strlen at the start to avoid doing it twice
|
Did my own optimization pass which saves 14 bytes if I counted right, let me know if anything doesn't make sense or I somehow broke something. Felt that would be easier than trying to point out individual changes in a review |
|
Thanks, it makes sense to me, and the test program works properly too. |
|
I'm not sure how I feel adding BSD-specific implementations. I can understand some POSIX functions, but an argument needs to be made before we decide to start pulling in random BSD stuff which clutters things and makes it hard for users to know what is actually available. I would prefer to only see C-standard compliant libc. |
|
|
|
quite a few of these POSIX functions are already available as Clang builtins too https://github.com/llvm/llvm-project/blob/release/15.x/clang/include/clang/Basic/Builtins.def |
This PR adds an implementation and tests for
strlcpy, and corrects its signature in string.h.strlcpyis a BSD variant of strncpy that ensures the destination is null-terminated. More info about strlcpy here: https://linux.die.net/man/3/strlcpy