mirror of
https://github.com/guezoloic/libft.git
synced 2026-01-25 00:34:15 +00:00
feat: add ft_strlcpy function
This commit is contained in:
20
ft_strlcpy.c
Normal file
20
ft_strlcpy.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
|
||||
{
|
||||
size_t length;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
length = ft_strlen(src);
|
||||
if (dstsize > 0)
|
||||
{
|
||||
while (dstsize - 1 > i && src[i])
|
||||
{
|
||||
dst[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[i] = '\0';
|
||||
}
|
||||
return (length);
|
||||
}
|
||||
8
libft.h
8
libft.h
@@ -80,4 +80,12 @@ void *ft_memcpy(void *dst, const void *src, size_t n);
|
||||
*/
|
||||
void *ft_memmove(void *dst, const void *src, size_t n);
|
||||
|
||||
/*
|
||||
strlcpy() copies up to dstsize - 1
|
||||
characters from the string src to
|
||||
dst, NUL-terminating the result if
|
||||
dstsize is not 0.
|
||||
*/
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user