-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
35 lines (32 loc) · 1.22 KB
/
ft_memmove.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lignigno <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/15 13:30:55 by lumfred #+# #+# */
/* Updated: 2021/10/18 16:42:26 by lumfred ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
size_t i;
char *ch1;
char *ch2;
if (dest == NULL || src == NULL)
return (NULL);
if (n == 0)
return (dest);
i = 0;
ch1 = (char *)dest;
ch2 = (char *)src;
if (ch1 > ch2)
while (n-- > 0)
ch1[n] = ch2[n];
else
while (i++ < n)
*ch1++ = *ch2++;
return (dest);
}