-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
86 lines (76 loc) · 1.96 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: juhagon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/06 08:53:59 by juhagon #+# #+# */
/* Updated: 2021/12/06 08:54:01 by juhagon ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
int ft_strlen(const char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned long int pos;
pos = 0;
if (!dest && !src)
return (dest);
while (pos < n)
{
*(unsigned char *)(dest + pos) = *(unsigned char *)(src + pos);
pos++;
}
return (dest);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *goal;
int len_1;
int len_2;
int len_goal;
if (!s1 || !s2)
return (0);
len_1 = ft_strlen((char *)s1);
len_2 = ft_strlen((char *)s2);
len_goal = len_1 + len_2;
goal = malloc(len_goal + 1);
if (!goal)
return (0);
ft_memcpy(goal, s1, len_1);
ft_memcpy(goal + len_1, s2, len_2);
goal[len_goal] = '\0';
free((void *)s1);
return (goal);
}
char *ft_strchr(const char *s, int c)
{
if (!s)
return (NULL);
while (*s != '\0')
{
if (*s == c)
return ((char *)s);
s++;
}
return (0);
}
char *ft_strdup(const char *src)
{
int len;
char *goal;
len = ft_strlen(src);
goal = malloc(len + 1);
if (!goal)
return (0);
ft_memcpy(goal, src, len + 1);
return (goal);
}