-
Notifications
You must be signed in to change notification settings - Fork 1
/
c_vector_memory.c
47 lines (42 loc) · 1.33 KB
/
c_vector_memory.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
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* c_vector_memory.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aaubin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/13 19:18:02 by aaubin #+# #+# */
/* Updated: 2014/02/13 19:18:18 by aaubin ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
static void cptb(char *ptr1, char *ptr2, size_t n)
{
while (n)
{
ptr1[n - 1] = ptr2[n - 1];
--n;
}
}
static void cpfw(char *ptr1, char *ptr2, size_t n)
{
while (n)
{
*ptr1 = *ptr2;
++ptr1;
++ptr2;
--n;
}
}
void *c_vector_memmove(void *s1, const void *s2, size_t n)
{
char *ptr1;
char *ptr2;
ptr1 = (char *)s1;
ptr2 = (char *)s2;
if (ptr1 > ptr2)
cptb(ptr1, ptr2, n);
else
cpfw(ptr1, ptr2, n);
return (s1);
}