-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
75 lines (65 loc) · 1.7 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oohnivch <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/25 15:00:55 by oohnivch #+# #+# */
/* Updated: 2024/04/29 19:02:13 by oohnivch ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(char const *s)
{
size_t i;
i = 0;
if (!s)
return (i);
while (s[i])
i++;
return (i);
}
size_t ft_nlcheck(char const *s)
{
size_t i;
if (!s)
return (0);
i = 0;
while (s[i] && s[i] != '\n')
i++;
return (s[i] == '\n');
}
void *ft_calloc(size_t nmemb, size_t size)
{
size_t total_size;
size_t i;
void *ptr;
char *p;
total_size = size * nmemb;
if (size && total_size / size != nmemb)
return (NULL);
ptr = malloc(total_size);
if (ptr == NULL)
return (NULL);
p = (char *)ptr;
i = 0;
while (i < total_size)
p[i++] = 0;
return (ptr);
}
size_t ft_linelen(char *buffer)
{
size_t i;
i = 0;
while (buffer[i] != '\n' && buffer[i] != '\0')
i++;
return (i + (buffer[i] == '\n'));
}
void ft_free(char **ptr)
{
if (!ptr || !*ptr)
return ;
free(*ptr);
*ptr = NULL;
}