Cub3D/libft/str/ft_strlcpy.c
2024-10-31 18:17:43 +01:00

40 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */
/* Updated: 2024/10/31 18:12:13 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Copies a string with size limit.
*
* @param dst The destination buffer.
* @param src The source string.
* @param size The maximum number of characters to copy.
*
* @return The total length of `src`.
*/
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
i = 0;
while (src[i] && i + 1 < size)
{
dst[i] = src[i];
i++;
}
if (size > 0)
{
dst[i] = '\0';
i++;
}
return (ft_strlen(src));
}