-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
89 lines (78 loc) · 1.9 KB
/
get_next_line_utils_bonus.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
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ialvarez <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/06 19:03:43 by ialvarez #+# #+# */
/* Updated: 2021/05/06 19:05:13 by ialvarez ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
void *ft_memcpy(void *dst, const void *src, size_t n)
{
unsigned char *a;
const unsigned char *b;
a = dst;
b = src;
if (!src && !dst)
return (NULL);
while (n > 0)
{
*a++ = *b++;
n--;
}
return (dst);
}
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
i++;
}
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *dst;
if (!s1 || !s2)
return (NULL);
dst = malloc(sizeof (char) * (ft_strlen(s1) + ft_strlen(s2)) + 1);
if (dst)
{
ft_memcpy(dst, s1, ft_strlen(s1));
ft_memcpy(dst + ft_strlen(s1), s2, ft_strlen(s2) + 1);
}
return (dst);
}
char *ft_strdup(const char *s1)
{
char *dst;
int i;
i = ft_strlen(s1);
dst = malloc(sizeof (char) * (i + 1));
if (!dst)
return (NULL);
ft_memcpy(dst, s1, i);
dst[i] = '\0';
return (dst);
}
char *ft_strchr(const char *s, int c)
{
int a;
int len;
char x;
x = c;
a = 0;
len = ft_strlen(s);
while (a < len + 1)
{
if (s[a] == x)
return ((char *)s + a);
a++;
}
return (NULL);
}