-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_next_line_utils.c
More file actions
64 lines (57 loc) · 1.62 KB
/
get_next_line_utils.c
File metadata and controls
64 lines (57 loc) · 1.62 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jihyjeon < jihyjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/21 18:59:38 by jihyjeon #+# #+# */
/* Updated: 2024/01/25 17:47:34 by jihyjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char *s)
{
size_t len;
if (!s)
return (0);
len = 0;
while (*(s + len))
len++;
return (len);
}
char *ft_strjoin(char *s1, char *s2, ssize_t blen)
{
char *new;
ssize_t len_s1;
len_s1 = ft_strlen(s1);
new = (char *)malloc(sizeof(char) * (len_s1 + blen + 1));
if (!(new))
return (0);
ft_memcpy(new, s1, len_s1);
ft_memcpy(new + len_s1, s2, blen);
*(new + len_s1 + blen) = 0;
return (new);
}
void *ft_memcpy(void *dst, void *src, size_t n)
{
unsigned char *d;
unsigned char *s;
d = dst;
s = (unsigned char *)src;
if (!d && !s)
return (0);
if (d < s || d >= (s + n))
{
while (n--)
*(d++) = *(s++);
}
else
{
d += n;
s += n;
while (n--)
*(--d) = *(--s);
}
return (dst);
}