#include <stdio.h>
#include <string.h>
unsigned int ft_strlen (char *str)
{
unsigned int i;
i = 0;
while (str[i] != '\0')
i++;
return i;
}
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
unsigned int j;
unsigned int i;
unsigned int len_dst;
unsigned int len_src;
j = ft_strlen(dst);
i = 0;
len_dst = ft_strlen(dst);
len_src = ft_strlen(src);
if (dstsize < 1)
return (len_src + dstsize);
while (src[i] && j < dstsize - 1)
{
dst[j] = src[i];
j++;
i++;
}
dst[j] = '\0';
if (dstsize < len_dst)
return (len_src + dstsize);
else
return (len_dst + len_src);
}
int main(void) {
char foo_src[7] = "Hello ";
char foo_dest[9] = "World! ";
printf("%d\n", ft_strlcat
(foo_dest
, foo_src
, 0)); ft_strlcat(foo_dest, foo_src, 9);
//strlcat(foo_dest, foo_src, 10);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCnVuc2lnbmVkIGludCBmdF9zdHJsZW4gKGNoYXIgKnN0cikKewogIHVuc2lnbmVkIGludCBpOwoKICBpID0gMDsKICB3aGlsZSAoc3RyW2ldICE9ICdcMCcpCiAgICBpKys7CiAgcmV0dXJuIGk7Cn0KCnNpemVfdAlmdF9zdHJsY2F0KGNoYXIgKmRzdCwgY29uc3QgY2hhciAqc3JjLCBzaXplX3QgZHN0c2l6ZSkKewoJdW5zaWduZWQgaW50CWo7Cgl1bnNpZ25lZCBpbnQJaTsKCXVuc2lnbmVkIGludAlsZW5fZHN0OwoJdW5zaWduZWQgaW50CWxlbl9zcmM7CgoJaiA9IGZ0X3N0cmxlbihkc3QpOwoJaSA9IDA7CglsZW5fZHN0ID0gZnRfc3RybGVuKGRzdCk7CglsZW5fc3JjID0gZnRfc3RybGVuKHNyYyk7CglpZiAoZHN0c2l6ZSA8IDEpCgkJcmV0dXJuIChsZW5fc3JjICsgZHN0c2l6ZSk7Cgl3aGlsZSAoc3JjW2ldICYmIGogPCBkc3RzaXplIC0gMSkKC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