-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
executable file
·87 lines (76 loc) · 1.84 KB
/
get_next_line_utils.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
85
86
87
/* ************************************************************************** */
/* */
/* :::::::: */
/* get_next_line_utils.c :+: :+: */
/* +:+ */
/* By: kris <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/05/20 18:44:23 by kris #+# #+# */
/* Updated: 2020/07/05 15:24:36 by kstallen ######## odam.nl */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
char *d;
const char *s;
if (dst == NULL && src == NULL)
return (dst);
d = dst;
s = src;
while (n)
{
*d = *s;
d++;
s++;
n--;
}
return (dst);
}
char *ft_strchr(const char *str, int c)
{
char *string;
int length;
string = (char *)str;
length = ft_strlen(string);
while (length >= 0)
{
if (string && *string == (char)c)
return (string);
string++;
length--;
}
return (NULL);
}
void *ft_memset(void *b, int c, size_t len)
{
int i;
i = 0;
while (i < (int)len)
{
((char *)b)[i] = (unsigned char)c;
i++;
}
return (b);
}
void *ft_memmalloc(size_t size)
{
void *ret;
ret = malloc(size);
if (ret == NULL)
return (NULL);
ft_memset(ret, 0, size);
return (ret);
}
char *ft_strdup(const char *s1)
{
int len;
char *s2;
len = ft_strlen(s1);
s2 = ft_memmalloc(len + 1);
if (s2 == NULL)
return (NULL);
ft_memcpy(s2, s1, len);
s2[len] = '\0';
return (s2);
}