-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
90 lines (80 loc) · 1.92 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/16 15:44:28 by julmuntz #+# #+# */
/* Updated: 2022/06/26 21:54:52 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char *s)
{
size_t i;
i = 0;
if (s == NULL)
return (0);
while (s[i])
i++;
return (i);
}
void *ft_memcpy(void *dst, void *src, size_t n)
{
size_t i;
char *d;
char *s;
i = 0;
s = (void *)src;
d = (void *)dst;
if (src == NULL && dst == NULL)
return (NULL);
while (n--)
{
d[i] = s[i];
i++;
}
return (dst);
}
char *ft_strjoin(char *s1, char *s2)
{
size_t i[3];
char *res;
if (s1 == NULL || s2 == NULL)
return (NULL);
i[1] = ft_strlen(s1);
i[2] = ft_strlen(s2);
res = (char *)malloc(i[1] + i[2] + 1);
if (res == NULL)
return (NULL);
ft_memcpy(res, s1, i[1]);
ft_memcpy(res + i[1], s2, i[2]);
res[i[1] + i[2]] = 0;
return (free(s1), res);
}
char *ft_strdup(char *s)
{
char *d;
char *t;
if (s == NULL)
return (NULL);
d = malloc((ft_strlen(s) + 1) * sizeof(char));
if (d == NULL)
return (NULL);
t = d;
while (*s)
*t++ = *s++;
*t = 0;
return (d);
}
char *ft_strchr(char *s, int c)
{
while (s && *s != (char)c)
{
if (*s == 0)
return (NULL);
s++;
}
return ((char *)s);
}