-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
79 lines (69 loc) · 1.82 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybolivar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/29 17:33:19 by ybolivar #+# #+# */
/* Updated: 2022/07/04 17:37:58 by ybolivar ### ########.fr */
/* */
/* ************************************************************************** */
#include"get_next_line.h"
void gnl_bzero(void *str, size_t len)
{
unsigned char *buf;
buf = str;
while (len--)
{
*buf++ = 0;
}
}
void *gnl_calloc(size_t count, size_t size)
{
void *ptr;
if (size >= SIZE_MAX || count >= SIZE_MAX)
return (NULL);
ptr = (void *)malloc(count * size);
if (ptr == NULL)
return (NULL);
gnl_bzero(ptr, (count * size));
return (ptr);
}
char *gnl_strchr(const char *s, int c)
{
while ((*s != '\0') && (*s != (char)c))
{
s++;
}
if (*s == (char)c)
{
return ((char *)s);
}
return (NULL);
}
size_t gnl_strlen(const char *s)
{
int i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}
char *gnl_strjoin(char const *s1, char const *s2)
{
char *join;
char *send;
if (!s1 || !s2)
return (NULL);
join = (char *)malloc((gnl_strlen(s1) + gnl_strlen(s2) + 1) * sizeof(char));
if (!join)
return (NULL);
send = join;
while (*s1)
*join++ = *s1++;
while (*s2)
*join++ = *s2++;
*join = '\0';
return (send);
}