-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
84 lines (75 loc) · 1.97 KB
/
get_next_line_utils_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gantonio <gantonio@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/16 20:54:10 by gantonio #+# #+# */
/* Updated: 2021/06/21 21:52:24 by gantonio ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
if (!str)
return (0);
while (str[i] != '\0')
i++;
return (i);
}
void *ft_memmove(void *dest, const void *src, size_t len)
{
unsigned char *ptr_dest;
const unsigned char *ptr_src;
size_t i;
ptr_dest = dest;
ptr_src = src;
i = 0;
if (dest == NULL && src == NULL)
return (NULL);
if (ptr_dest > ptr_src)
while (len-- > 0)
ptr_dest[len] = ptr_src[len];
else
{
while (i < len)
{
ptr_dest[i] = ptr_src[i];
i++;
}
}
return (dest);
}
int ft_is_new_line(const char *str)
{
int i;
i = 0;
if (!str)
return (0);
while (str[i])
{
if (str[i] == '\n')
return (1);
i++;
}
return (0);
}
char *ft_strjoin(char const *s1, char const *s2)
{
size_t len;
char *repo;
if (!s1 && !s2)
return (0);
len = ft_strlen((char *)s1) + ft_strlen((char *)s2) + 1;
repo = malloc(sizeof(char) * len);
if (!repo)
return (0);
ft_memmove(repo, s1, ft_strlen((char *)s1));
ft_memmove(repo + ft_strlen((char *)s1), s2, ft_strlen((char *)s2));
repo[len - 1] = '\0';
free((char *)s1);
return (repo);
}