Hello i just faced a problem when testing an implementation of strlcpy
long unsigned int ft_strlcpy(char *dst, const char *src, unsigned int len)
{
unsigned int l;
unsigned int i;
i = 0;
while (i < len - 1)
{
if (*src != '\0')
*dst++ = *src++;
i++;
}
*dst = '\0';
return i + 1;
}
i did a test with the original strlcpy but i didn't get the same result src = "string", len = 6 output of my strlcpy
return value = 6
dst = strin
output of the original strlcpy
return value = 10
dst = strin
the result is the same in dst but in the return value should be the length of the string trying to make
From the documentation
You're returning the length of the resulting string, not the length it would have been without the
lenlimit.Save
strlen(src)in a variable and return that at the end.Also, the
lenparameter and the return type should besize_t.