strlcpy/strlcat api for portability's sake.

those functions differently than the strn* ones as
they do not pad with zero to remaining bytes but guarantees
a null terminator.
This commit is contained in:
David Carlier
2023-03-24 09:44:33 +00:00
parent 0144ea1a9d
commit 34f2fff983
3 changed files with 36 additions and 0 deletions
+10
View File
@@ -16,4 +16,14 @@ int main(void) {
dst[19] = 0;
strncpy(dst, "strncpy should work here too", 10);
puts(dst);
// The string should be properly terminated regardless
char ndst[28];
size_t r = strlcpy(ndst, "strlcpy works!", 28);
puts(ndst);
printf("copied %lu\n", r);
r = strlcat(ndst, " and strlcat!", 28);
puts(ndst);
printf("copied %lu\n", r);
}