-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
85 lines (75 loc) · 1.9 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: telias-p <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/25 16:43:50 by telias-p #+# #+# */
/* Updated: 2021/04/05 20:31:44 by telias-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strclen(const char *str, const char c)
{
unsigned int i;
i = 0;
while (str[i] && str[i] != c)
i++;
return (i);
}
size_t ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
void ft_strdel(char **str)
{
if (*str && str)
{
free(*str);
*str = NULL;
}
}
void *ft_memcpy(void *dest, const void *src, size_t n)
{
size_t i;
i = 0;
if (!dest && !src)
return (0);
while (i < n)
{
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
i++;
}
return (dest);
}
char *ft_strjoin_free(char *dest, char *src)
{
char *new_str;
int i;
int dest_len;
int src_len;
if (!dest || !src)
return (NULL);
i = -1;
dest_len = ft_strlen(dest);
src_len = ft_strlen(src);
new_str = malloc((dest_len + src_len + 1) * sizeof(*new_str));
if (!new_str)
{
ft_strdel(&dest);
return (NULL);
}
while (dest[++i])
new_str[i] = dest[i];
i = -1;
while (src[++i])
new_str[dest_len++] = src[i];
new_str[dest_len] = '\0';
ft_strdel(&dest);
return (new_str);
}