-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_mem2.c
74 lines (65 loc) · 1.65 KB
/
ft_mem2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_mem2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lgillot- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/19 01:33:03 by lgillot- #+# #+# */
/* Updated: 2015/11/19 01:36:14 by lgillot- ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include <stdlib.h>
#include <ft_mem.h>
void *ft_memchr(const void *s, int c, size_t n)
{
const void *s_it;
s_it = s;
while (s_it < s + n)
{
if (*(const unsigned char *)s_it == (unsigned char)c)
{
return (void *)s_it;
}
s_it++;
}
return (NULL);
}
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
const unsigned char *it1;
const unsigned char *it2;
int diff;
it1 = (unsigned char *)s1;
it2 = (unsigned char *)s2;
if (n == 0)
{
return (0);
}
while (n)
{
diff = *it1 - *it2;
if (diff)
{
return (diff);
}
it1++;
it2++;
n--;
}
return (0);
}
void *ft_memalloc(size_t size)
{
void *buf;
buf = malloc(size);
if (buf)
ft_bzero(buf, size);
return (buf);
}
void ft_memdel(void **ap)
{
free(*ap);
*ap = NULL;
}