-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memmove.c
More file actions
67 lines (61 loc) · 1.67 KB
/
ft_memmove.c
File metadata and controls
67 lines (61 loc) · 1.67 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_memmove.c :+: :+: */
/* +:+ */
/* By: farodrig <farodrig@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/12/04 10:22:08 by farodrig #+# #+# */
/* Updated: 2021/02/28 20:44:52 by farodrig ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
static void *copy_from_back_to_front(
void *dest,
const void *src,
size_t len
)
{
while (len)
{
len--;
((char *)dest)[len] = ((char *)src)[len];
}
return (dest);
}
static void *copy_from_front_to_back(
void *dest,
const void *src,
size_t len
)
{
size_t i;
i = 0;
while (i < len)
{
((char *)dest)[i] = ((char *)src)[i];
i++;
}
return (dest);
}
/*
** Copies len bytes from string src to string dest. The two strings may overlap;
** the copy is always done in a non-destructive manner.
** Returns the original value of dest.
*/
void *ft_memmove(void *dest, const void *src, size_t len)
{
if (!dest && !src)
{
return (dest);
}
if (dest > src)
{
copy_from_back_to_front(dest, src, len);
}
else
{
copy_from_front_to_back(dest, src, len);
}
return (dest);
}