-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
112 lines (101 loc) · 2.21 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 15:33:39 by ael-maaz #+# #+# */
/* Updated: 2024/01/17 17:19:58 by ael-maaz ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *s)
{
int count;
count = 0;
while (s[count] != '\0')
{
count++;
}
return (count);
}
void *ft_memfunc(void *b, void *s, int c, size_t len)
{
size_t i;
i = 0;
if (c == 0)
{
while (i < len)
{
((unsigned char *)b)[i++] = '\n';
}
return (b);
}
else
{
if (!b && !s)
return (NULL);
while (i < len)
{
((unsigned char *)b)[i] = ((unsigned char *)s)[i];
i++;
}
return (b);
}
}
char *ft_strdup(const char *s1)
{
char *p;
int i;
i = 0;
p = malloc(sizeof(char) * (ft_strlen(s1) + 1));
if (!p)
return (NULL);
while (s1[i])
{
p[i] = s1[i];
i++;
}
p[i] = '\0';
return (p);
}
char *ft_strjoin(char *s1, char *s2)
{
size_t length;
char *p;
int i;
int j;
i = -1;
j = 0;
if (s1 == NULL && s2 == NULL)
return (NULL);
else if (s1 == NULL)
return (ft_strdup(s2));
else if (s2 == NULL)
return (ft_strdup(s1));
length = ft_strlen(s1) + ft_strlen(s2);
p = (char *)malloc(sizeof(char) * (length + 1));
if (!p)
return (NULL);
while (s1[++i])
p[i] = s1[i];
while (s2[j])
p[i++] = s2[j++];
p[length] = '\0';
return (p);
}
char *ft_strchr(const char *s, int c)
{
int i;
i = 0;
while (s[i] != '\0')
{
if ((unsigned char)c == s[i])
return ((char *)s + i);
i++;
}
if (s[i] == (unsigned char)c)
return ((char *)s + i);
return (0);
}