ft_strlcpy - gabrielcoelhodacunha-old/42sp-libft GitHub Wiki
Description
Copies up to dstsize - 1
characters from src
to dst
null terminating dst
.
Implementation
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t src_len;
src_len = ft_strlen(src);
if (src_len < dstsize)
// Copies `src` to `dst` including the null terminating character
ft_memcpy(dst, src, src_len + 1);
else if (dstsize)
{
// Copies `dstsize - 1` bytes from `src' to `dst`
ft_memcpy(dst, src, dstsize - 1);
// Null terminates `dst`
dst[dstsize - 1] = '\0';
}
return (ft_strlen(src));
}