-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
88 lines (77 loc) · 1.88 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agaliste <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/04 09:09:13 by agaliste #+# #+# */
/* Updated: 2021/08/29 04:29:39 by agaliste ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
char *ft_strjoin(const char *s1, const char *s2)
{
char *str;
unsigned int i;
unsigned int j;
if (s1 == NULL || s2 == NULL)
return (NULL);
str = malloc((sizeof(char) * ft_strlen(s1) + ft_strlen(s2)) + 1);
if (str == NULL)
return (NULL);
i = 0;
j = 0;
while (s1[i])
str[j++] = s1[i++];
i = 0;
while (s2[i])
str[j++] = s2[i++];
str[ft_strlen(s1) + ft_strlen(s2)] = '\0';
return (str);
}
char *ft_strchr(const char *s, int n)
{
char *ret;
if (!s)
return (NULL);
ret = (char *)s;
while (*ret != n)
{
if (*ret == '\0')
return (NULL);
ret++;
}
return (ret);
}
void ft_bzero(void *s, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
((char *)s)[i] = 0;
i++;
}
}
void *ft_memcpy(void *dst, const void *src, size_t n)
{
size_t i;
i = 0;
if (!dst && !src)
return (NULL);
while (i < n)
{
((char *)dst)[i] = ((const char *)src)[i];
i++;
}
return (dst);
}