-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
42 lines (39 loc) · 1.33 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: malexand <malexand@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/05/01 20:55:54 by alex #+# #+# */
/* Updated: 2017/02/16 17:34:25 by malexand ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
char *tmp;
char *dest0;
char *src0;
size_t count;
count = 0;
src0 = (char *)src;
dest0 = (char *)dest;
if (dest == src || n == 0 ||
(tmp = (char *)malloc(sizeof(char) * n)) == NULL)
return (dest);
while (count < n)
{
tmp[count] = src0[count];
count++;
}
count = 0;
while (count < n)
{
dest0[count] = tmp[count];
count++;
}
free(tmp);
tmp = NULL;
return (dest);
}