-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils.c
74 lines (65 loc) · 1.86 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
/* ************************************************************************** */
/* */
/* _.._ . . */
/* get_next_line_utils.c .' .-'` * */
/* / / + * */
/* By: ldel-val <[email protected] | | * */
/* \ '.___.; + */
/* Created: 2024/10/17 16:40:04 by ldel-val '._ _.' . . */
/* Updated: 2024/10/23 13:07:49 by ldel-val `` */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
size_t ft_strlen(const char *s)
{
size_t i;
if (!s || !*s)
return (0);
i = 0;
while (s[i])
i++;
return (i);
}
size_t ft_strlcpy(char *dst, char *src, size_t size)
{
size_t i;
i = 0;
if (size == 0)
return (ft_strlen(src));
while (i < size - 1 && src[i])
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (ft_strlen(src));
}
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dstlen;
size_t srclen;
dstlen = ft_strlen(dst);
srclen = ft_strlen(src);
if (dstlen > size)
return (srclen + size);
dst += dstlen;
size -= dstlen;
while (size-- > 1 && *src)
*dst++ = *src++;
*dst = '\0';
return (srclen + dstlen);
}
void *ft_calloc(size_t nmemb, size_t size)
{
char *allocated_memory;
size_t i;
if (size && nmemb > SIZE_MAX / size)
return (NULL);
i = size * nmemb;
allocated_memory = (char *)malloc(nmemb * size);
if (!allocated_memory)
return (NULL);
while (i-- > 0)
allocated_memory[i] = '\0';
return (allocated_memory);
}