-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_next_line_utils_bonus.c
110 lines (99 loc) · 2.2 KB
/
get_next_line_utils_bonus.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* get_next_line_utils_bonus.c :+: :+: */
/* +:+ */
/* By: opelman <[email protected]> +#+ */
/* +#+ */
/* Created: 2024/01/02 15:13:39 by opelman #+# #+# */
/* Updated: 2024/01/02 15:13:42 by opelman ######## odam.nl */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
void *ft_alloc(size_t size)
{
char *out;
size_t i;
i = 0;
out = malloc(size);
if (out == NULL)
return (NULL);
while (i < size)
{
out[i] = '\0';
i++;
}
return (out);
}
size_t ft_strlcpy(char *dst, char *src, size_t size)
{
size_t slen;
size_t net_size;
if (dst == NULL || src == NULL)
return (0);
slen = ft_strlen(src);
net_size = size - 1;
if (size == 0)
return (slen);
if (size > slen)
net_size = slen;
ft_memmove(dst, src, net_size);
*(dst + net_size) = '\0';
return (slen);
}
void *ft_memmove(void *dest, void *src, size_t n)
{
unsigned char *temp_src;
unsigned char *temp_dest;
size_t i;
temp_src = src;
temp_dest = dest;
if (src < dest)
{
while (n > 0)
{
*(temp_dest + n - 1) = *(temp_src + n - 1);
n--;
}
}
if (dest < src)
{
i = 0;
while (i < n)
{
*(temp_dest + i) = *(temp_src + i);
i++;
}
}
return (dest);
}
size_t ft_strlen(void *c)
{
size_t len;
char *temp;
len = 0;
temp = (char *)c;
if (temp == NULL)
return (0);
while (temp[len] != '\0')
len ++;
return (len);
}
char *ft_strchr(void *s, int c)
{
char *a;
char c_char;
if (s == NULL)
return (NULL);
a = (char *)s;
c_char = (char)c;
if (c_char == '\0')
return (a + ft_strlen(s));
while (*a != '\0')
{
if (*a == c_char)
return (a);
a++;
}
return (NULL);
}