-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_next_line_utils.c
More file actions
93 lines (82 loc) · 1.95 KB
/
get_next_line_utils.c
File metadata and controls
93 lines (82 loc) · 1.95 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ldiaz-ra <ldiaz-ra@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 21:37:29 by ldiaz-ra #+# #+# */
/* Updated: 2023/10/26 11:37:33 by ldiaz-ra ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *str)
{
size_t i;
i = 0;
while (str[i] != '\0')
i++;
return (i);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *str_new;
char *init;
if (!s1 && !s2)
return (NULL);
str_new = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
init = str_new;
if (!str_new)
return (NULL);
while (*s1)
*str_new++ = *s1++;
while (*s2)
*str_new++ = *s2++;
*str_new = '\0';
return (init);
}
char *ft_strchr(const char *s, int c)
{
char character;
int slen;
int i;
slen = ft_strlen(s);
character = (char)c;
i = 0;
while (i <= slen)
{
if (s[i] == character)
return ((char *)&s[i]);
i++;
}
return (0);
}
void ft_bzero(void *s, size_t n)
{
unsigned char *ptr;
ptr = s;
if (n != 0)
{
while (n--)
{
*ptr++ = '\0';
}
}
}
void *ft_calloc(size_t count, size_t size)
{
void *memory;
memory = (void *)malloc(count * size);
if (!memory)
return (NULL);
else
{
if (!size)
return ((void *)memory);
else
{
ft_bzero (memory, (count * size));
return ((void *)memory);
}
}
}