-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_mem.c
84 lines (73 loc) · 1.86 KB
/
ft_mem.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_mem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lgillot- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/19 01:33:05 by lgillot- #+# #+# */
/* Updated: 2015/11/19 01:35:52 by lgillot- ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include <ft_mem.h>
void *ft_memset(void *b, int c, size_t len)
{
void *it;
it = b;
while (it < b + len)
{
*((unsigned char *)it) = (unsigned char)c;
it++;
}
return (b);
}
void ft_bzero(void *s, size_t n)
{
if (n != 0)
{
ft_memset(s, 0, n);
}
}
void *ft_memcpy(void *dst, const void *src, size_t n)
{
char *dst_it;
const char *src_it;
dst_it = dst;
src_it = src;
while (n)
{
*dst_it++ = *src_it++;
n--;
}
return (dst);
}
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
void *stop;
size_t pos_after_stop;
stop = ft_memchr(src, c, n);
pos_after_stop = stop - src + 1;
ft_memcpy(dst, src, stop ? pos_after_stop : n);
return (stop ? dst + pos_after_stop : NULL);
}
void *ft_memmove(void *dst, const void *src, size_t n)
{
char *dst_it;
const char *src_it;
if (src > dst)
{
ft_memcpy(dst, src, n);
}
else
{
dst_it = dst + n - 1;
src_it = src + n - 1;
while (n)
{
*dst_it-- = *src_it--;
n--;
}
}
return (dst);
}