-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
103 lines (91 loc) · 2.06 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmita <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/06 10:23:51 by mmita #+# #+# */
/* Updated: 2023/03/11 13:47:22 by mmita ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str && str[i])
{
i++;
}
return (i);
}
/**
* @brief
*
* @param s1
* @param s2
* @return char*
*/
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
if (!s)
return (0);
while (s[i] != '\0')
{
if (s[i] == (char)c)
return ((char *)&s[i]);
i++;
}
if ((char)c == '\0')
return ((char *)(s + i));
return (NULL);
}
void ft_bzero(void *s, size_t n)
{
size_t counter;
counter = 0;
while (n != 0 && counter++ <= (n - 1))
{
*(char *)s = '\0';
s++;
}
}
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
ptr = malloc(count * size);
if (ptr == NULL)
return (NULL);
ft_bzero(ptr, (count * size));
return (ptr);
}
char *ft_strjoin(char *s1, char *s2)
{
char *str;
size_t c1;
size_t c2;
size_t strlen_s1;
size_t strlen_s2;
if (!s1 && !s2)
return (NULL);
strlen_s1 = ft_strlen(s1);
strlen_s2 = ft_strlen(s2);
str = (char *)malloc(sizeof(char) * (strlen_s1 + strlen_s2 + 1));
if (!str)
return (0);
c1 = 0;
while (c1 < strlen_s1)
{
str[c1] = s1[c1];
c1++;
}
c2 = 0;
while (c2 < strlen_s2)
str[c1++] = s2[c2++];
str[c1] = '\0';
free (s1);
return (str);
}