ft_strlcpy: initial implementation

This commit is contained in:
Khaïs COLIN 2024-10-15 14:54:04 +02:00
parent 29fbed55a3
commit a7ffedf420
2 changed files with 39 additions and 2 deletions

36
ft_strlcpy.c Normal file
View file

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/15 14:47:09 by kcolin #+# #+# */
/* Updated: 2024/10/15 14:53:42 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int min(t_size a, t_size b)
{
if (a > b)
return (b);
return (a);
}
t_size strlcpy(char *dst, const char *src, t_size size)
{
t_size i;
i = 0;
while (src[i] != 0)
{
if (i < size)
dst[i] = src[i];
i++;
}
if (size > 0)
dst[min(i, size - 1)] = '\0';
return (i);
}