-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_memmove.c
42 lines (39 loc) · 1.35 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
36
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_memmove.c :+: :+: */
/* +:+ */
/* By: ksmorozo <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/09 11:25:39 by ksmorozo #+# #+# */
/* Updated: 2021/07/07 12:17:34 by ksmorozo ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stddef.h>
void *ft_memmove(void *dest, const void *src, size_t n)
{
unsigned char *source;
unsigned char *destination;
int count;
if (src == dest)
return (dest);
source = (unsigned char *)src;
destination = (unsigned char *)dest;
count = n - 1;
if (source < destination)
{
while (count >= 0)
{
destination[count] = source[count];
count--;
}
}
while (count >= 0)
{
*destination = *source;
count--;
source++;
destination++;
}
return (dest);
}