-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_next_line_utils.c
More file actions
70 lines (62 loc) · 1.7 KB
/
get_next_line_utils.c
File metadata and controls
70 lines (62 loc) · 1.7 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sryou <sryou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/08 18:02:05 by sryou #+# #+# */
/* Updated: 2022/08/16 14:33:07 by sryou ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
char *ft_free(char **line)
{
if (line != 0 && *line != 0)
{
free(*line);
*line = 0;
}
return (0);
}
int ft_strmylen(char *str)
{
int idx;
if (str == 0)
return (0);
idx = 0;
while (str[idx])
idx++;
return (idx);
}
void ft_strmycat(char *dst, char *src, int dstsize, int srcsize)
{
int idx;
idx = 0;
dst = dst + dstsize;
while (idx < srcsize)
{
*dst = *src;
dst++;
src++;
idx++;
}
*dst = '\0';
}
int ft_strmyjoin(char **line, char *buffer)
{
int len1;
int len2;
char *mkstr;
len1 = ft_strmylen(*line);
len2 = ft_strmylen(buffer);
mkstr = (char *)malloc(sizeof(char) * (len1 + len2 + 1));
if (mkstr == 0)
return (0);
mkstr[0] = '\0';
ft_strmycat(mkstr, *line, 0, len1);
ft_strmycat(mkstr, buffer, len1, len2);
ft_free(line);
*line = mkstr;
return (len1 + len2);
}