ft_strlcpy
Subject
Understandable explanation
What this function does is pretty simple in that it's made to copy one string to another but with a small catch, it always NUL-terminate the string.
If you give a dstsize
long enough to NUL-terminate the string without truncating it, strlcpy()
will simply copy the string, as you'd do with strcpy()
. If you don't give a dstsize
long enough, it will copy dstsize - 1
characters from the source into the destination, adding the NUL-terminating character after that.
The strlcpy()
function always returns the length of the string that it tried to create, this is the length of src
, even if you have to truncate the string to NUL-terminate it.
Hints
I implemented this the same way it is implemented in the Apple's C version. Check the sources for the link to the page.
Commented solution
Sources
Last updated
Was this helpful?