-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
88 lines (77 loc) · 2.07 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gariadno <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 14:18:10 by gariadno #+# #+# */
/* Updated: 2020/02/14 14:18:14 by gariadno ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(const char *s)
{
size_t len;
len = 0;
while (s[len])
len++;
return (len);
}
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
char *ori;
char *desty;
if (!dst && !src)
return (NULL);
i = 0;
desty = (char *)dst;
ori = (char *)src;
while (i < n)
{
desty[i] = ori[i];
i++;
}
return (desty);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
if (!s1 || !(str = (char *)malloc(ft_strlen(s1) + ft_strlen(s2) + 1)))
return (NULL);
ft_memcpy(str, s1, ft_strlen(s1));
ft_memcpy(str + ft_strlen(s1), s2, ft_strlen(s2));
str[ft_strlen(s2) + ft_strlen(s1)] = '\0';
return (str);
}
char *ft_strdup(const char *s1)
{
char *str;
size_t i;
if (!(str = (char *)malloc((ft_strlen(s1) + 1) * sizeof(char))))
return (NULL);
i = 0;
while (s1[i])
{
str[i] = s1[i];
i++;
}
str[i] = '\0';
return (str);
}
char *ft_substr(char const *s, unsigned int start, size_t len)
{
unsigned int i;
char *str;
if (!s || !(str = (char *)malloc((len + 1) * sizeof(char))))
return (NULL);
i = 0;
while (s[start + i] && i < len && start < ft_strlen(s))
{
str[i] = s[start + i];
i++;
}
str[i] = '\0';
return (str);
}