-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
91 lines (82 loc) · 1.98 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mheinke <mheinke@student.42abudhabi.ae> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/13 11:09:26 by mheinke #+# #+# */
/* Updated: 2023/09/19 10:27:32 by mheinke ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
if (!str)
return (0);
while (str[i])
i++;
return (i);
}
char *ft_strchr(const char *str, int c)
{
size_t i;
i = 0;
if (!str)
return (NULL);
while (str[i])
{
if (str[i] == (char)c)
return ((char *)&str[i]);
i++;
}
if ((char)c == '\0')
return ((char *)&str[i]);
return (NULL);
}
char *ft_strdup(const char *s)
{
int i;
int j;
char *str;
i = 0;
j = ft_strlen(s);
str = (char *)malloc(sizeof(*str) * (j + 1));
if (!str)
return (NULL);
while (i < j)
{
str[i] = s[i];
i++;
}
str[i] = '\0';
return (str);
}
char *ft_strjoin(char *buffer, char *content)
{
size_t i;
size_t j;
char *result;
if (!buffer)
return (ft_strdup(content));
if (!content)
return (ft_strdup(buffer));
i = 0;
result = (char *)malloc(sizeof(char) * (ft_strlen(buffer)
+ ft_strlen(content)) + 1);
if (!result)
return (NULL);
while (buffer && buffer[i])
{
result[i] = buffer[i];
i++;
}
j = 0;
while (content && content[j])
result[i++] = content[j++];
result[i] = '\0';
free(buffer);
return (result);
}