libft/str/ft_strlcpy.c
Raphael 905ffd4b72
refactor: only the usefull header
- Removing all 'libft.h' mention
- Using the include only on the files needed by
2025-09-01 18:45:33 +02:00

41 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */
/* Updated: 2025/09/01 17:52:00 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "str.h"
#include <unistd.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));
}