-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem_op.c
72 lines (63 loc) · 1.66 KB
/
mem_op.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_op.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asarandi <asarandi@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/10 19:15:55 by asarandi #+# #+# */
/* Updated: 2017/12/27 16:59:43 by asarandi ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
char *ft_strdup(const char *s1)
{
char *mem;
mem = (char *)malloc(sizeof(char) * ft_strlen(s1) + 1);
if (mem == NULL)
return (NULL);
return (ft_strcpy(mem, s1));
}
void *ft_memalloc(size_t size)
{
unsigned char *p;
size_t i;
if ((p = malloc(size)) == NULL)
return (NULL);
i = 0;
while (i < size)
{
p[i] = 0;
i++;
}
return (p);
}
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned char *d;
const unsigned char *s;
size_t i;
d = dest;
s = src;
i = 0;
while (i < n)
{
d[i] = s[i];
i++;
}
return (void *)(dest);
}
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
const unsigned char *m;
i = 0;
m = s;
while (i < n)
{
if (m[i] == (unsigned char)c)
return (void *)(&m[i]);
i++;
}
return (NULL);
}