-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
91 lines (82 loc) · 2.14 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: splattje <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/11/01 13:08:22 by splattje #+# #+# */
/* Updated: 2023/11/06 11:03:05 by splattje ######## odam.nl */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *str)
{
size_t index;
index = 0;
if (!str)
return (0);
while (str[index])
index++;
return (index);
}
char *ft_strchr(const char *str, int c)
{
size_t index;
index = 0;
if (!str)
return (NULL);
while (str[index])
{
if (str[index] == (char)c)
return ((char *)&str[index]);
index++;
}
if ((char)c == '\0')
return ((char *)&str[index]);
return (NULL);
}
char *ft_strdup(const char *s)
{
int index;
int str_len;
char *str;
index = 0;
str_len = ft_strlen(s);
str = (char *)malloc(sizeof(*str) * (str_len + 1));
if (!str)
return (NULL);
while (index < str_len)
{
str[index] = s[index];
index++;
}
str[index] = '\0';
return (str);
}
char *ft_strjoin(char *buffer, char *content)
{
size_t index;
size_t sec_index;
char *result;
if (!buffer)
return (ft_strdup(content));
if (!content)
return (ft_strdup(buffer));
index = 0;
result = (char *)malloc(sizeof(char) * (ft_strlen(buffer)
+ ft_strlen(content)) + 1);
if (!result)
return (NULL);
while (buffer && buffer[index])
{
result[index] = buffer[index];
index++;
}
sec_index = 0;
while (content && content[sec_index])
result[index++] = content[sec_index++];
result[index] = '\0';
free(buffer);
return (result);
}