2024-10-15 13:51:09 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* ft_memcpy.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2024/10/15 13:38:05 by kcolin #+# #+# */
|
2024-10-22 12:10:08 +02:00
|
|
|
/* Updated: 2024/10/22 12:03:47 by kcolin ### ########.fr */
|
2024-10-15 13:51:09 +02:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "libft.h"
|
2024-10-22 12:10:08 +02:00
|
|
|
#include <stdlib.h>
|
2024-10-15 13:51:09 +02:00
|
|
|
|
2024-10-16 15:20:28 +02:00
|
|
|
void *ft_memcpy(void *dest, const void *src, size_t n)
|
2024-10-15 13:51:09 +02:00
|
|
|
{
|
2024-10-16 15:20:28 +02:00
|
|
|
size_t i;
|
2024-10-15 13:51:09 +02:00
|
|
|
|
2024-10-22 12:10:08 +02:00
|
|
|
if ((dest == NULL || src == NULL) && n > 0)
|
|
|
|
|
return (dest);
|
2024-10-15 13:51:09 +02:00
|
|
|
i = 0;
|
2024-10-15 14:44:11 +02:00
|
|
|
while (i < n)
|
2024-10-15 13:51:09 +02:00
|
|
|
{
|
2024-10-15 14:44:11 +02:00
|
|
|
((char *)dest)[i] = ((char *)src)[i];
|
2024-10-15 13:51:09 +02:00
|
|
|
i++;
|
|
|
|
|
}
|
2024-10-15 14:44:11 +02:00
|
|
|
return (dest);
|
2024-10-15 13:51:09 +02:00
|
|
|
}
|
2024-10-22 12:10:08 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "libft.h"
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
char dest[20] = "AAAAAAAAAAAAAAAAAAA";
|
|
|
|
|
char src[20] = "Hello there";
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
printf("%p\n", ft_memcpy(dest, src, 0));
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < 20)
|
|
|
|
|
{
|
|
|
|
|
printf("%d\t%c\n", dest[i], dest[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
printf("%p\n", ft_memcpy(dest, src, 15));
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < 20)
|
|
|
|
|
{
|
|
|
|
|
printf("%d\t%c\n", dest[i], dest[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
printf("%p\n", memcpy(dest, src, 15));
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < 20)
|
|
|
|
|
{
|
|
|
|
|
printf("%d\t%c\n", dest[i], dest[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf("%p\n", ft_memcpy(NULL, NULL, 15));
|
|
|
|
|
}
|
|
|
|
|
*/
|