diff --git a/ft_memcpy.c b/ft_memcpy.c new file mode 100644 index 0000000..142f026 --- /dev/null +++ b/ft_memcpy.c @@ -0,0 +1,18 @@ +#include "libft.h" + +void *ft_memcpy(void *dst, const void *src, size_t n) +{ + size_t i; + char *srctmp; + char *dsttmp; + + i = 0; + srctmp = (char *)src; + dsttmp = (char *)dst; + while (i < n) + { + dsttmp[i] = srctmp[i]; + i++; + } + return (dst); +} diff --git a/libft.h b/libft.h index 7375bd7..0e72e0f 100644 --- a/libft.h +++ b/libft.h @@ -61,4 +61,14 @@ void *ft_memset(void *b, int c, size_t len); */ void ft_bzero(void *s, size_t n); +/* + The memcpy() function copies n bytes + from memory area src to memory area dst. + If dst and src overlap, behavior is + undefined. Applications in which dst and + src might overlap should use memmove(3) + instead. +*/ +void *ft_memcpy(void *dst, const void *src, size_t n); + #endif