-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
93 lines (82 loc) · 2.02 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
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alcierra <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/16 18:35:32 by alcierra #+# #+# */
/* Updated: 2021/10/17 12:25:35 by alcierra ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char *s)
{
size_t sz;
sz = 0;
while (s[sz])
sz++;
return (sz);
}
size_t ft_strlcpy(char *dst, const char *src, size_t sz)
{
size_t i;
i = 0;
if (sz == 0)
return (ft_strlen((char *) src));
while (src[i])
{
if (i == sz - 1)
break ;
dst[i] = src[i];
i++;
}
dst[i] = 0;
return (ft_strlen((char *) src));
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
int len1;
int len2;
if (!s1 || !s2)
return (NULL);
len1 = ft_strlen((char *) s1);
len2 = ft_strlen((char *) s2);
str = (char *) malloc(sizeof(char) * (len1 + len2 + 1));
if (str == NULL)
return (NULL);
ft_strlcpy(str, s1, len1 + 1);
ft_strlcpy(str + len1, s2, len2 + 1);
return (str);
}
char *ft_strdup(const char *s1)
{
char *str;
int len;
int i;
len = ft_strlen((char *) s1);
str = (char *) malloc((len + 1) * sizeof(char));
if (str == NULL)
{
return (str);
}
i = 0;
while (i < len)
{
str[i] = s1[i];
i++;
}
str[i] = 0;
return (str);
}
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
while (s[i] != c && s[i] != 0)
i++;
if (s[i] || c == 0)
return ((char *)s + i);
return (NULL);
}