✅strlcpy
- Copy a NULL terminated string into a sized buffer
dst
에 src
를 size
- 1 만큼 복사.
💾함수 원형
size_t strlcpy(char *dst, const char *src, size_t dstsize);
💻Parameters
dst
: Where to copy the string to
src
: Where to copy the string from
dstsize
: size of destination buffer
💻Return value
💾함수 구현
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t src_len;
size_t i;
src_len = 0;
i = 0;
while(src[src_len] != '\0')
src_len++;
if (dstsize == 0)
return (src_len);
while (src[i] != '\0' && i < (dstsize - 1))
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (src_len);
}