40 lines
1.4 KiB
C
40 lines
1.4 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* ft_strlcat.c :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: pbonilla <eirodeis.lepnj@gmail.com> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2020/11/09 19:11:10 by pbonilla #+# #+# */
|
||
|
/* Updated: 2020/12/03 17:41:01 by pbonilla ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "libft.h"
|
||
|
|
||
|
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||
|
{
|
||
|
size_t dst_size;
|
||
|
size_t src_size;
|
||
|
size_t i;
|
||
|
|
||
|
i = 0;
|
||
|
src_size = 0;
|
||
|
dst_size = 0;
|
||
|
while (src[src_size])
|
||
|
src_size++;
|
||
|
if (size == 0)
|
||
|
return (src_size);
|
||
|
while (dst_size < size && dst[dst_size])
|
||
|
dst_size++;
|
||
|
if (size <= dst_size)
|
||
|
return (size + src_size);
|
||
|
while (size && (--size - dst_size) && src[i])
|
||
|
{
|
||
|
dst[dst_size + i] = src[i];
|
||
|
i++;
|
||
|
}
|
||
|
dst[dst_size + i] = 0;
|
||
|
return (src_size + dst_size);
|
||
|
}
|