-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
92 lines (82 loc) · 1.92 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jeongrol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/10 19:54:36 by jeongrol #+# #+# */
/* Updated: 2023/01/16 17:39:01 by jeongrol ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *ft_strdup(const char *src)
{
int src_len;
char *temp;
int i;
src_len = ft_strlen(src);
temp = (char *)malloc(sizeof(char) * (src_len + 1));
if (!temp)
return (NULL);
i = 0;
while (src[i] != '\0')
{
temp[i] = src[i];
i++;
}
temp[i] = '\0';
return (temp);
}
void free_all(char *a, char *b)
{
free(a);
free(b);
}
int ft_strlen(const char *s)
{
int i;
if (!s)
return (0);
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
int ft_linelen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
{
if (s[i] == '\n')
return (i + 1);
i++;
}
return (-1);
}
char *ft_strjoin(char *buff, char *tmp, int tmp_len)
{
char *join_buff;
int buff_len;
int i;
buff_len = ft_strlen(buff);
join_buff = (char *)malloc(sizeof(char) * (buff_len + tmp_len + 1));
if (!join_buff)
return (NULL);
i = 0;
while (i < buff_len)
{
join_buff[i] = buff[i];
i++;
}
i = 0;
while (i < tmp_len)
{
join_buff[buff_len + i] = tmp[i];
i++;
}
join_buff[buff_len + i] = '\0';
free(buff);
return (join_buff);
}