Details
- Reviewers
michaelrj lntue - Commits
- rGb1183305f882: [libc] Add strlcat
Diff Detail
Event Timeline
libc/src/string/strlcat.cpp | ||
---|---|---|
19–20 | this doesn't quite work because the return value always needs to be strlen(dst)+strlen(src). This means you always need to find the full length of dst. | |
libc/test/src/string/strlcat_test.cpp | ||
33 | as discussed above the return value of strlcat should always be strlen(dst)+strlen(src), so this should be 4. |
libc/src/string/strlcat.cpp | ||
---|---|---|
19–20 | Described below | |
libc/test/src/string/strlcat_test.cpp | ||
33 | No because the buffer size was passed as 1, so strlcat only reads 1 char from buf and uses that as the size. Per the man page "Note, however, that if strlcat() traverses size characters without finding a NUL, the length of the string is considered to be size and the destination string will not be NUL-terminated (since there was no space for the NUL)." |
LGTM
libc/test/src/string/strlcat_test.cpp | ||
---|---|---|
33 | oops, you're right. The source I was going off of was wrong, and this way matches the existing implementation. |
libc/src/string/strlcat.cpp | ||
---|---|---|
23 | nit: it looks like len is only used here, so you could move the call to string_length inside this if to save time on the other branch. |
this doesn't quite work because the return value always needs to be strlen(dst)+strlen(src). This means you always need to find the full length of dst.