-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
92 lines (82 loc) · 1.99 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: mkaraden <[email protected] # : # */
/* # # # # # # */
/* Created: 2022/12/03 11:25:17 by mkaraden # # # # */
/* Updated: 2022/12/05 17:13:34 by mkaraden ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char *str)
{
size_t i;
i = 0;
if (!str)
return (0);
while (str[i] != '\0')
i ;
return (i);
}
size_t ft_strlcpy(char *dst, char *src, size_t dstsize)
{
size_t i;
i = 0;
if (dstsize > 0)
{
while (src[i] && (i < (dstsize - 1)))
{
dst[i] = src[i];
i ;
}
dst[i] = '\0';
}
return (ft_strlen(src));
}
char *ft_strjoin(char *s1, char *s2)
{
char *rt;
int s1_len;
int s2_len;
if (!s1)
{
s1 = (char *)malloc(1 * sizeof(char));
s1[0] = '\0';
}
if (!s2)
return (NULL);
s1_len = (ft_strlen((char *)s1));
s2_len = (ft_strlen((char *)s2));
rt = (char *)malloc((s1_len s2_len 1) * sizeof(char));
if (rt == NULL)
return (NULL);
ft_strlcpy(rt, s1, s1_len 1);
ft_strlcpy(&rt[s1_len], s2, s2_len 1);
free(s1);
return (rt);
}
int check_newline(char *ptr)
{
if (!ptr)
return (0);
while (*ptr)
{
if (*ptr == '\n')
return (1);
ptr ;
}
return (0);
}
char *ft_strdup(char *str)
{
char *rt;
size_t len;
len = ft_strlen(str);
rt = malloc(sizeof(char) * (len 1));
if (!rt)
return (0);
ft_strlcpy(rt, str, len 1);
return (rt);
}